This is a simple plugin MooTools that answers most of your geo questions. It wraps the following services in a simple interface:

Syntax


 new MooGeo(what,options);

Implements:

Options, Events

Arguments:

what
Is a thing you want to analyse - this could be the URL to a web document, a text, an IP, a pair of latitude and longitude information, 'visitor' to detect the geographic location of the current visitor or 'ipvisitor' to grab visitor's IP.
options
instance'options see below

Options

endpoint
endpoint YQL Service API
format
the format that you want to receive the data
injectScript
the location where you want to inject the script

Events

request
This event is fired whenever is sent a request
complete
This event is fired whenever the request has been completed and the actually instance receives a response from the server
success
This event is fired whenever the request has been completed and the actually instance receives a response from the server
failure
This event is fired whenever is receved a message of error from the server
error
This event is fired whenever is receved a message of error from the server

Returns

(Object) A new Object MooGeo.

Samples:

Usage

To use this geo plugin, simply include it in your document.

Find the user (using the W3C geolocation API)


 new MooGeo('visitor',{
     onComplete: function(o) {
        console.log(o);
     }  
 });        
       

Find the user's IP


 new MooGeo('ipvisitor',{
     onComplete: function(o) {
        console.log(o);
     }  
 });        
       

Get the place from an IP number


 new MooGeo('188.25.34.67',{
     onComplete: function(o) {
        console.log(o);
     }  
 });        
       

Get all the geo locations from a certain URL

You can scrape a certain document URL for geographical locations:


 new MooGeo('http://mootools.net/developers/',{
     onComplete: function(o) {
        console.log(o);
     }  
 });        

       

Getting location information from latitude/longitude

You can get all kind of data from a latitude/longitude pair. You can either send them in as two parameters or as an array:


 new MooGeo(44.4333,26.1000,{
     onComplete: function(o) {
        console.log(o.place.name + ',' + o.place.country.content);
     }  
 });        
       

 new MooGeo([44.4333,26.1000],{
     onComplete: function(o) {
        console.log(o.place.name + ',' + o.place.country.content);
     }  
 });        
       

Getting the geographical location from a text

You can send an arbitrary text to the object to find the geographical information in it:


 new MooGeo('bucharest,ro',{
     onComplete: function(o){
       console.log(o.place.name + '(' + o.place.centroid.latitude + ',' + o.place.centroid.longitude);  
     }
 });