      1 (function(){
      2
      3 /**
      4  * Initialise our provider. This function should only be called
      5  * from within mapstraction code, not exposed as part of the API.
      6  * @private
      7  */
      8 var init = function() {
      9 	this.invoker.go('init');
     10 };
     11
     12 /**
     13  * Geocoder instantiates a geocoder with some API choice
     14  * @name mxn.Geocoder
     15  * @constructor
     16  * @param {String} api The API to use, currently only 'mapquest' is supported
     17  * @param {Function} callback The function to call when a geocode request returns (function(waypoint))
     18  * @param {Function} error_callback The optional function to call when a geocode request fails
     19  * @exports Geocoder as mxn.Geocoder
     20  */
     21 var Geocoder = mxn.Geocoder = function (api, callback, error_callback) {
     22 	this.api = api;
     23 	this.geocoders = {};
     24 	this.callback = callback;
     25 	this.error_callback = error_callback || function(){};
     26
     27 	// set up our invoker for calling API methods
     28 	this.invoker = new mxn.Invoker(this, 'Geocoder', function(){ return this.api; });
     29 	init.apply(this);
     30 };
     31
     32 mxn.addProxyMethods(Geocoder, [
     33
     34 	/**
     35 	 * Geocodes the provided address.
     36 	 * @name mxn.Geocoder#geocode
     37 	 * @function
     38 	 * @param {Object} address Address hash, keys are: street, locality, region, country.
     39 	 */
     40 	'geocode',
     41
     42 	'geocode_callback'
     43
     44 ]);
     45
     46 /**
     47  * Change the geocoding API in use
     48  * @name mxn.Geocoder#swap
     49  * @param {String} api The API to swap to
     50  */
     51 Geocoder.prototype.swap = function(api) {
     52 	if (this.api == api) { return; }
     53
     54 	this.api = api;
     55 	if (!this.geocoders.hasOwnProperty(this.api)) {
     56 		init.apply(this);
     57 	}
     58 };
     59
     60 })();