views:

39

answers:

2

Hi,

I will use the following javascript to display a Google Map Window in a webpage.

<script language = 'javascript'"> 
    function initialize() 
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(35.904173, 14.433396), 16);
        map.setUIToDefault();
      }
    } 
</script> 

I would like to read the coordinates from a db, to generate the map using PHP, but how is it possible to use the retrieved(eg $lat = xxx and $lon = yyy) values into the javascript?

+2  A: 

What about a hard insert?

<script language = 'javascript'"> 
    function initialize() 
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(<?php echo $lat.', '.$lon; ?>), 16);
        map.setUIToDefault();
      }
    } 
</script> 
Jhonny D. Cano -Leftware-
+1 for beating me to it
John Conde
it was just time... i've had just bad rep points today ;)
Jhonny D. Cano -Leftware-
thanks to both of you .... it worked!
mouthpiec
glad 2 be helpful !!!
Jhonny D. Cano -Leftware-
+2  A: 

1) Use ajax to retrieve the values

2) Embed the PHP in your javascript:

<script language = 'javascript'"> 
    function initialize() 
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(<?php echo $lat; ?>, <?php echo $lon; ?>), 16);
        map.setUIToDefault();
      }
    } 
</script> 
John Conde
I think that latitude should be the first parameter :-)
Luc M
Ooooops! My bad! :O Fixed.
John Conde