Skip to content

Instantly share code, notes, and snippets.

@rufuspollock
Last active February 12, 2022 22:50
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rufuspollock/4994760 to your computer and use it in GitHub Desktop.
Save rufuspollock/4994760 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);
});
@ttresslar
Copy link

Hey, I'm having an issue running this code. FIrst, on line 10, there is an extra bracket, so that gives me a syntax error. But even without the bracket, I can't get it to run. Any suggestions?

@rufuspollock
Copy link
Author

@ttresslar i've fixed the bracket. I suspect this no longer runs as mapquestapi no longer supports that url ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment