Skip to content

A simple wrapper JavaScript library to provide a single interface for a variety of third-party geocoding services.

Notifications You must be signed in to change notification settings

straup/js-geocoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a simple wrapper JavaScript library to provide a single interface for a
variety of third-party geocoding services.

Additionally, you can specify multiple providers in a single request each of
which will be tried until one returns a successful response.

Sort of like this:

	var doThisOnSuccess = function(rsp){
		var div = document.getElementById('output');
		div.innerHTML = rsp.lat + ',' + rsp.lon + ',' + rsp.zoom;
	};

	var doThisIfNot = function(rsp){
		var div = document.getElementById('output');
		div.innerHTML = rsp.provider + ' failed with error: ' + rsp.message;
	};

	var providers = ['geocoder.us' , 'google', 'placemaker', 'cloudmade', 'bing'];

	var args = {
		'providers' : providers,
		'flickr_apikey' : 'YER_FLICKR_APIKEY',
		'cloudmade_apikey' : 'YER_CLOUDMADE_APIKEY',
                'enable_logging' : true,
	};

	var query = '475 Sansome San Francisco CA';

	var geo = new info.aaronland.geo.Geocoder(args);
	geo.geocode(query, doThisOnSuccess, doThisIfNot);

If you have logging turned on, you'd see something like this:

	[geocoder] geocode w/ geocoder.us
	[geocoder] geocoder.us failed: geocoder.us support not complete
	[geocoder] geocoding failed, trying again w/ google
	[geocoder] geocode w/ google
	[geocoder] google failed: missing libraries
	[geocoder] geocoding failed, trying again w/ placemaker
	[geocoder] geocode w/ placemaker
	[geocoder] query dispatched to placemaker
	[geocoder] placemaker returned OK

You can also not pass a list of 'providers' and have the package define its own
list based on the availability of client libraries and things like API keys. The
order of precedence for automagic 'provider' lists is:

	* Google

	* Cloudmade

	* Flickr

	* Placemaker

	* Bing

That's pretty much all the interface will ever look like. As of this writing it
mostly works but it's also incomplete and there are probably bugs.

Currently supported providers are:

	* Bing (http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2)

	* Cloudmade (http://cloudmade.com/products/web-maps-lite)

	* Flickr (http://github.com/straup/js-flickr-api/tree/master)

	* Google (http://code.google.com/apis/maps/documentation/v3)

	* Y! Placemaker (http://icant.co.uk/jsplacemaker/)

Note that you will need to include the service-specific JavaScript libraries
yourself.

Soon to be supported include:

	* Geocoder.us

	* Geonames


About

A simple wrapper JavaScript library to provide a single interface for a variety of third-party geocoding services.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published