Thursday, March 11th, 2010
YQL Geo library – all your geo needs in pure JavaScript
I just finished doing some talks on geo hacking (slides are available here) and how to use some of the Geo technologies Yahoo and Google provide as part of a University gig in Atlanta.
As a lot of the students liked the idea of APIs like GeoPlanet and Placemaker but had a hard time getting their head around them I thought it a good idea to build a small JavaScript library that does the job for them.
I give you the YQL Geo library (and its source on GitHub). Using this library you can do the following:
- Detecting the visitor's location with the W3C geo API and with IP as a fallback
- Find geo location from text
- Find location from lat/lon pair
- Find locations in a certain web document (by URL)
- Get the location for a certain IP number
And all of that in pure JavaScript. For example:
'paris,fr',
function(o){
console.log(o);
}
)
Will get you:
"lang":"en-US",
"uri":"http://where.yahooapis.com/v1/place/615702",
"woeid":"615702",
"placeTypeName":{
"code":"7",
"content":"Town"
},
"name":"Paris",
"country":{
"code":"FR",
"type":"Country",
"content":"France"
},
"admin1":{
"code":"",
"type":"Region",
"content":"Ile-de-France"
},
"admin2":{
"code":"FR-75",
"type":"Department",
"content":"Paris"
},
"admin3":null,
"locality1":{
"type":"Town",
"content":"Paris"
},
"locality2":null,
"postal":null,
"centroid":{
"latitude":"48.856918",
"longitude":"2.341210"
},
"boundingBox":{
"southWest":{
"latitude":"48.658291",
"longitude":"2.086790"
},
"northEast":{
"latitude":"49.046940",
"longitude":"2.637910"
}
}
}
Other uses:
This gets the name and the country of a lat/lon pair:
alert(o.place.name + ',' + o.place.country.content);
})
This finds the visitor's location (on W3C geo API enabled browsers it asks them to share it - otherwise it detects the IP and locates this one on the planet)
alert(o.place.name + ',' + o.place.country.content +
' (' + o.place.centroid.latitude + ',' +
o.place.centroid.longitude + ')'
);
});
Read all about it on my blog and enjoy!







Chris, your blog throws a warning about malware in Chromium. When I visit anyway, I get some pdf file downloaded automatically (myreadme.php.pdf) which I deleted on the assumption that it’s malware. Chromium then gives a warning box saying “this site wants to download multiple files to your computer: allow/deny”.
All of which is to say, I think you’ve got some funky shit going down at your blog that you ought to take a look at.
If media temple have a vulnerability nothing in the world is safe anymore… :D
Awesome.