views:

706

answers:

4

This is puzzling me. I'm using Google Map's Geocoding to find locations. I am attempting to use the example here, which is from Google, and it is just not working for me.


Error:

http://maps.gstatic.com/intl/en_us/mapfiles/159e/maps2.api/main.js
Line 174
var point = new GLatLng(,);


Code:

<script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key='.$config['locations.gMaps.key'].'" type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key='.$config['locations.gMaps.key'].'" type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script>

<style type="text/css">
    @import url("http://www.google.com/uds/css/gsearch.css");
    @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
</style>
<script type="text/javascript">

    function addListener(element, baseName, handler) {
     if (element.addEventListener)
      element.addEventListener(baseName, handler, false);
     else if (element.attachEvent)
      element.attachEvent("on"+baseName,handler);
    }

    var map'.$num.'; 

    function initialize'.$num.'() 
    {

     if (GBrowserIsCompatible()) 
     {
      map'.$num.' = new GMap2(document.getElementById("google_map'.$num.'"),{mapTypes:[G_HYBRID_MAP]});
      var point = new GLatLng('.$row->LocationLat.','.$row->LocationLon.');
      map'.$num.'.setCenter(new GLatLng('.$row->LocationLat.','.$row->LocationLon.'),4);
      var mapControl = new GMapTypeControl();
      map'.$num.'.addControl(mapControl);
      map'.$num.'.addControl(new GLargeMapControl());
      map'.$num.'.addControl(new GOverviewMapControl());
      map'.$num.'.enableDoubleClickZoom();
      map'.$num.'.enableScrollWheelZoom();
      var bounds = new GLatLngBounds;

      var myIcon = new GIcon();
      myIcon.image = "http://www.google.com/mapfiles/marker.png";
      myIcon.iconAnchor = new GPoint((markerImage1.width/2),markerImage1.height);



      bounds.extend(point);
      setBounds(map'.$num.',bounds);        

      var address = "' . $address . '";


      var geocoder = new GClientGeocoder();
      showAddress(address, geocoder);

     }
    }

    function showAddress(address, geocoder) {
      geocoder.getLatLng(
     address,
     function(point) {
       if (!point) {
      alert(address + " not found");
       } else {
      map'.$num.'.setCenter(point, 13);
      var marker = new GMarker(point);
      map'.$num.'.addOverlay(marker);
      marker.openInfoWindowHtml(address);
       }
     }
      );
    }


    function setBounds(map'.$num.',bounds) 
    {
     map'.$num.'.setZoom(15);
     map'.$num.'.setCenter(bounds.getCenter());
    }     

    function chargement() 
    { 
     markerImage1 = new Image(); 
     markerImage1.src = "http://www.google.com/mapfiles/marker.png";
     setTimeout("initialize'.$num.'()", 500); 
    }

    addListener(window, "load", chargement);
</script>

My code is generated by PHP, so when there is an ' that means I'm opening or closing the string that is holding the JavaScript.

+1  A: 

Maybe I didn't get it, but

var point = new GLatLng(,);

is not valid javascript

It should be either

var point = new GLatLng(param1, param2);

or

var point = new GLatLng();

or

var point = new GLatLng(null,null);

... depending on what the GLatLng constructor is

marcgg
I know that, I don't have access to that google javascript that's throwing the error.
Malfist
oooh... where do you call the function? what parameters?
marcgg
I'm assuming geocoder.getLatLng calls it in the function showAddress
Malfist
It looks like the php generating the calling function is off
marcgg
i've echoed it, it looks like it should.
Malfist
Could you add the caller in your question? Did you tried running the firebug debugger? If not, give it a try
marcgg
yeap, I always use firebug :)The javascript is just being added to a variable called $map if there is a location in the database, and then it's being echoed.
Malfist
I just changed the code to mirror what google map's example was. I have no idea why the other program left all that other stuff in it. It's never used. Everything works now.
Malfist
weird... well at least it's working now!
marcgg
A: 

This statement:

var point = new GLatLng(,);

Is not correct because there isn't a lat or lng number specified. This is because this statement:

var point = new GLatLng('.$row->LocationLat.','.$row->LocationLon.');

Is incorrect. I'd try something like:

var point = new GLatLng(<?php echo $row->LocationLat . ',' . $row->LocationLon; ?>);

If that doesn't work, then $row->LocationLat or $row->LocationLon are possibly empty.

Peter
That call for point is commented out. I'm not using it. The problem with with the showAddress function.
Malfist
A: 

Problem 1- The function showAddress() is not closed.

Problem 2 - your map object needs to be defined outside of the functions so that showAddress() can access it.

Problem 3 - The references to the map object inside of showAddress() are incorrect

Chris B
I fixed those three issues, and it's still throwing the same error, will update code.
Malfist
@Malfist - could you show us the executed php code? That way we can see if there's any problems with what your php is outputting.
Chris B
I just changed the code to mirror what google map's example was. I have no idea why the other program left all that other stuff in it. It's never used. Everything works now.
Malfist
I don't understand your PHP syntax. var map'.$num.'; ?? Do you mean to use var map<?=$num?>; ?
Chris B
No, as I said in the question, the how thing is a string. I'm just opening the string, and inserting a PHP variable. It then echos the string to the browser.
Malfist
Gotcha. Glad it's working now.
Chris B
A: 

check if the php string you are printing into the html+js exists in the first place. php generates the htm and sends it to the user, for now on it's htm+javascript problem. it looks like a javascript problem, but you really generated a wrong syntax with php to begin with, because you tried to print something problematic and it printed an empty space. always be careful of that, be sure of what you print.