0

is there any javascript code out there that will take a location as a string, for example like "Vancouver, British Columbia, Canada" and return the longitudinal and lateral coordinates? I am trying to build a map and I need something that will convert my list of locations into the correct coordinates. Any ideas?

Thanks

3 Answers 3

0

Here's some code from my application using jQuery, this is used to handle a form which has an input field 'location_search' with the address in it:

function setLocationFormSubmit(event) {
  event.preventDefault();
  $.getJSON(
    'http://maps.googleapis.com/maps/api/geocode/json',
    {'address': $('#location_search').val(), 'sensor': 'false'},
    function (json, textSuccess) {
      if (json.status == 'OK') {
            console.log('Longitude, latitude: ' + json.results[0].geometry.location.lng + ',' + json.results[0].geometry.location.lat);
        } else {
            alert('Location not found');
        }
    }
  ).error(function() {
    alert('Problem connecting to server.');
  });
  return false;
}

Note that Google limits the number of queries from an IP address but I've never come up to the limit even with quite a lot of testing.

0

Consider the Google Maps JavaScript API:

http://code.google.com/apis/maps/documentation/javascript/maptypes.html

0

You can use the Google Maps API to geocode via an AJAX call.

Your Answer

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

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