Here’s a novel idea (stolen from AppDen‘s Twitter feed fetch class) – extend the mootools-more’s JSONP class and setup some quick and easy geolocation lookups through pidgets.com and YQL (yahoo query language).
Here they are, 3 mini classes. First one uses the client’s IP address (or an optional ip supplied by options) to fetch geolocation info from http://geoip.pidgets.com/. The second instance fetches extended information on a place / city by location from Yahoo’s geoplaces DB, including things like local district, council authority, county and so forth, something that I find useful when creating quick signup forms for users and PAF lookups are not in the budget. The final class was simple test to fetch relevant timezone info of any latitude + longitude combination. It offers local time, offset from GMT or DST etc, but nothing that Date.get(“gmtoffset”) can’t accomplish anyway).
Request.geoLocation = new Class({ // gets basic info such as country and latitude data Extends: Request.JSONP, options: { ip: $empty(), // default is user but you can lookup anything. url: "http://geoip.pidgets.com/?format=json", }, initialize: function(options) { this.parent(options); if (this.options.ip.length) this.options.url = this.options.url += "&ip=" + this.options.ip }, success: function(data, script) { this.parent(data, script); } }); Request.getPlaceInfo = new Class({ // return json data with extended information of a place / location. Extends: Request.JSONP, options: { url: "http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text='{location}'&format=json", }, initialize: function(location, options) { this.parent(options); this.options.url = this.options.url.substitute({location: location}); }, success: function(data, script) { this.parent(data, script); } }); Request.timeZone = new Class({ // return local timezone related date from geo coordinates Extends: Request.JSONP, options: { url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fws.geonames.org%2Ftimezone%3Flat%3D{latitude}%26lng%3D{longitude}'&format=json" }, initialize: function(latitude, longitude, options){ this.parent(options); this.options.url = this.options.url.substitute({latitude: latitude, longitude: longitude}); }, success: function(data, script) { this.parent(data, script); } });
Here is a quick example of how it can be used on a form. Note you need mootools-more with JSONP for it to work.
GitHub flavoured markdown enabled.