jakebur01 Posted April 25, 2007 Share Posted April 25, 2007 i'm trying to get my google map to work. I'm passing variables to this page so i will get a map for the correct user. I've never tried to put php inside javascript. I'm not getting a view of the map with this yet. I need some help. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <?php $key = "mykey"; $conn = mysql_connect("localhost", "myuser", "mypass"); $db = mysql_select_db("jhearnsberger"); $query = "SELECT id, Address, City, State FROM smithssc WHERE id=$id"; $result = mysql_query($query) or die(mysql_error()); while (list($id, $Address, $City, $State) = mysql_fetch_row($result)) { $mapaddress = urlencode("$Address $City $State"); $url = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key"; $page = file_get_contents($url); $xml = new SimpleXMLElement($page); list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->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 GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(<?php $latitude ?>, <?php $longitude ?>), 13); } } //]]> </script> </head> <body onload="load()" onunload="GUnload()"> <div id="map" style="width: 500px; height: 300px"></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/ Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 How about <?php=$latitude ?> and <?php=$longitude ?> Note the = sign Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/#findComment-237709 Share on other sites More sharing options...
jakebur01 Posted April 25, 2007 Author Share Posted April 25, 2007 still no view with this map.setCenter(new GLatLng(<?php = $latitude ?>, <?php = $longitude ?>), 13); Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/#findComment-237714 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Take out those spaces should be exactly as I posted first Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/#findComment-237721 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Wait, Ive just discovered that <?php=$var?> only works with short tags ie: <?=$var?> Try using echo instead <?php echo"$latitude"; ?> and <?php echo "$longitude"; ?> Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/#findComment-237723 Share on other sites More sharing options...
jakebur01 Posted April 25, 2007 Author Share Posted April 25, 2007 OHMAN! It worked like a charm! Thanks for taking the time to help me. `Jake Link to comment https://forums.phpfreaks.com/topic/48552-solved-php-inside-javascript/#findComment-237727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.