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?

link|flag

52% accept rate

2 Answers

up vote 2 down vote accepted

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> 
link|flag
+1 for beating me to it – John Conde Apr 9 at 18:54
it was just time... i've had just bad rep points today ;) – Jhonny D. Cano -Leftware- Apr 9 at 19:01
thanks to both of you .... it worked! – mouthpiec Apr 9 at 19:21
glad 2 be helpful !!! – Jhonny D. Cano -Leftware- Apr 9 at 19:42

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> 
link|flag
I think that latitude should be the first parameter :-) – Luc M Apr 9 at 19:24
Ooooops! My bad! :O Fixed. – John Conde Apr 9 at 19:39

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.