Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierrelorioux/8703685 to your computer and use it in GitHub Desktop.
Save pierrelorioux/8703685 to your computer and use it in GitHub Desktop.
// the location we want to GeoCode
var location = 'London';
// we are using MapQuest's Nominatim service
var geocode = 'http://open.mapquestapi.com/search?format=json&q=' + location;
// use jQuery to call the API and get the JSON results
$.getJSON(geocode, function(data) {
// get lat + lon from first match
var latlng = [data[0].lat, data[0].lon]]
console.log(latlng);
// let's stringify it
var latlngAsString = latlng.join(',');
console.log(latlngAsString);
// the full results JSON
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment