0
votes

I'm trying to use the Google Geocoder API to get me a Latitude and Longitude to use in the Google Places API. First things first, how do I code the url of the API so it returns the JSON string? I thought it would be something like a jquery load, but that doesn't work. So I have this nice url that returns the information I need but just dumps a bunch of json data. How do I capture the data?

http://maps.googleapis.com/maps/api/geocode/address=12308&sensor=false

function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.googleapis.com/maps/api/geocode/address=12308&sensor=false";
  document.body.appendChild(script);
  resultjson = script
  console.log(resultjson);
}
1
I don't think the Google geocoding API has a JSONP access method, which would be required for something like this to work. - Pointy

1 Answers

0
votes

You can use the geocoder without the JSONP support but you have to use their Maps library instead:

Add this script tag to your HTML:

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

Then, add the following JS:

var geocoder = new google.maps.Geocoder();
geocoder.geocode(
    {address: "37203" }, 
    function(dataObject, statusObject) {
        console.log(dataObject);
    }
);