0

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;v=2&amp;key='.$config['locations.gMaps.key'].'" type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&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
  • Not Found The requested URL /intl/en_us/mapfiles/159e/map2.api/main.js was not found on this server. Commented Jul 7, 2009 at 17:51

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

8 Comments

I know that, I don't have access to that google javascript that's throwing the error.
oooh... where do you call the function? what parameters?
I'm assuming geocoder.getLatLng calls it in the function showAddress
It looks like the php generating the calling function is off
i've echoed it, it looks like it should.
|
0

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.

1 Comment

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

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

5 Comments

I fixed those three issues, and it's still throwing the same error, will update code.
@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.
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.
I don't understand your PHP syntax. var map'.$num.'; ?? Do you mean to use var map<?=$num?>; ?
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.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.