views:

20

answers:

2

I have the following code to fetch lattitude and longitude for given address but the permission to google url is denied .

function getlatlng(address, callback) { var addressval = address; var address; var url; var googleUrl = "http://maps.google.com/maps/api/geocode/json?"; var sensor = "&sensor=false";

            if (addressval != null && addressval != "" && addressval.length != 0) {

                address = "address=" + encodeURIComponent(addressval);

                $.ajax({
                    url: googleUrl + address + sensor,
                    type: "POST",
                    async: false,
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    success: function(longlatJson) {

                        var jsonObj = JSON.parse(JSON.stringify(longlatJson));
                        var lat = jsonObj.results[0].geometry.location.lat;
                        var lng = jsonObj.results[0].geometry.location.lng;
                        cb(lat, lng);
                    },
                    error: function() { alert("unable to conect to google server"); }
                });
            }

        }

This will be my function call to getlatlng for the given address

getlatlng(address, function(lat, lng) { alert(lat); alert(lng); ............... ...............

                });
+1  A: 

I don't see any reference to an API key in your code; do you send it with your requests ?

cxnull
I have it this will be reference to api key
mahesh
mahesh
So is it working now ?
cxnull
The code which i have written works fine with internet explorer 6.0 but not with internet explorer 8 and mozilla firefox what may the problem for this .
mahesh
+1  A: 

You don't need a key for v3.

The problem is that the Google Maps JSON web service does not use jsonp so you can't use it how you are becuase you are hitting the cross domain policy of browsers.

You either need to have your server do that request (via wget or something) and then pass the results back to the browser or instead use the Google Maps API geocoder and that will handle it for you.

You can read more here http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

skarE
The code which i have written works fine with internet explorer 6.0 but not with internet explorer 8 and mozilla firefox what may the problem for this .
mahesh