jakebur01 Posted April 25, 2007 Share Posted April 25, 2007 I got my google map working here. I was trying to add an info window to it. When I enter my variable $Address in all I get back is null. I had to do that urlencode on my variable earlier in the script. How can I pass my variable down correctly so I will be able to display my info in the info window? <?php // Your Google Maps API key $key = "mykey"; // Connect to the MySQL database $conn = mysql_connect("localhost", "myuser", "mypass"); // Select the database $db = mysql_select_db("mydb"); // Query the table $query = "SELECT id, Address, City, State FROM smithssc WHERE id=$id"; $result = mysql_query($query) or die(mysql_error()); // Loop through each row, submit HTTP request, output coordinates while (list($id, $Address, $City, $State) = mysql_fetch_row($result)) { $mapaddress = urlencode("$Address $City $State"); // Desired address $url = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key"; // Retrieve the URL contents $page = file_get_contents($url); // Parse the returned XML file $xml = new SimpleXMLElement($page); // Parse the coordinate string list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates); // Output the coordinates //echo "latitude: $latitude, longitude: $longitude <br />"; } ?> <script src="http://maps.google.com/maps?file=api&v=2&key=mykey" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GMapTypeControl()); map.addControl(new GLargeMapControl()); map.setCenter(new GLatLng(<?php echo"$latitude"; ?>,<?php echo "$longitude"; ?>), 14); map.openInfoWindow(map.getCenter(), document.createTextNode(<?php echo"$Address"; ?>)); } } //]]> </script> Quote Link to comment https://forums.phpfreaks.com/topic/48569-solved-problem-with-variables/ Share on other sites More sharing options...
btherl Posted April 25, 2007 Share Posted April 25, 2007 What do you mean by "When I enter my variable $Address in all I get back is null." ? What do you get if you print out $mapaddress and $url? Quote Link to comment https://forums.phpfreaks.com/topic/48569-solved-problem-with-variables/#findComment-237932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.