Geous.js: Geolocation made easy

In terms of potential and controversy, HTML5’s location-awareness is about as hot as its gets.

On the one hand, the [Geolocation API](<a href=) makes it ridiculously easy for applications to leverage a user’s immediate geographic context. On the other, the privacy and security concerns raised by instant access to a person’s physical location are substantial. And for good reason: by itself, the only intrinsic functionality exposed by the API is the ability to determine a user’s physical location.

When coupled with additional data, however, this information becomes much more useful. It might be used, for instance, to provide local points of interest or offer access to images or notes shared locally by other users in the area.

For some time now, I’ve been using Geous.js to simplify a few of the most basic tasks associated with geolocation and provide a tidy interface for handling location data. At its present (mostly) stable state, key features include:

  • Geolocation support
  • Basic geocoding helpers
  • Deferred loading of location-related services (e.g., Google Maps API)
  • Convenient structures for location and address data
  • Built-in fallbacks for older browsers

Together, these features enable developers to smoothly obtain a user’s location (if available), convert the location to a plain-text address, and manage the loading of third-party geo-related services. And it’s all wrapped up in a tidy interface that skips the basics and lets you get straight down to the good stuff.

Let’s try it out!

*You can see the following in action in the *[Geous Demo](http://rjzaworski.com/projects/geous/demo.html)
To include Geous and use it to ensure the Maps API is available, you might write:
<script src="https://raw.github.com/rjz/geous.js/master/src/geous.js"></script>
<script>
geous.withMaps(function(){
    alert('Maps API is now available..');
});
</script>

A similar call can obtain the user’s location:

geous.withLocation(function(){
    alert('..and a location, too!');
});

To use both together (and expose a geous.Location object with the current user’s address), you would just use:

geous.withMe(function(){
    alert('I\'m viewing this site from ' + geous.Me.address );
});

More Information

Featured