Jump to content

[SOLVED] php inside javascript


jakebur01

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.