Request.YQL + Google GeoCoding
Get the place name from lon/lat
HTML
<p id="location">Locating ...</p>
JavaScript
Request.YQL = new Class({
Extends: Request.JSONP,
options: {
url: 'http://query.yahooapis.com/v1/public/yql?q=',
data: {
format: 'json',
env: 'store://datatables.org/alltableswithkeys'
}
},
initialize: function(options) {
this.setOptions(options);
this.options.url = this.options.url + encodeURIComponent(this.options.query);
this.running = false;
this.requests = 0;
this.triesRemaining = [];
}
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
// the magical query
var yqlQuery = "select * from google.geocoding where q=\"{latitude},{longitude}\"".substitute(position.coords);
// make the YQL call
new Request.YQL({
query: yqlQuery,
onSuccess: function(result) {
document.id('location').set('text', result.query.results.json.Placemark[1].address);
}
}).send();
});
}