1 if (Garmin == undefined) var Garmin = {};
  2 /** Copyright � 2007 Garmin Ltd. or its subsidiaries.
  3  *
  4  * Licensed under the Apache License, Version 2.0 (the 'License')
  5  * you may not use this file except in compliance with the License.
  6  * You may obtain a copy of the License at
  7  *
  8  *    http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an 'AS IS' BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  * 
 16  * @fileoverview Garmin.Geocode A place-holder for goecoding services.
 17  * 
 18  * @author developer.connect.at.garmin.com
 19  * @version 1.0
 20  */
 21 /** Currently just a wrapper for Google geocode service.  This code could go into GarminDevicecontrol.js 
 22  * but it would create Google object dependencies.
 23  *
 24  * @class Garmin.Geocode
 25  * @constructor 
 26  */
 27 Garmin.Geocode = function(){}; //just here for jsdoc
 28 Garmin.Geocode = Class.create();
 29 Garmin.Geocode.prototype = {
 30 
 31 	/** Prototype constructor
 32 	 */
 33 	initialize: function() {
 34     	this.geocoder = new GClientGeocoder();
 35 		this._broadcaster = new Garmin.Broadcaster();
 36 	},
 37 	
 38 	/** Takes an address and uses geocoding service to get waypoint.
 39      * Registered listeners will receive either a 'onFinishedFindLatLon(Garmin.Waypoint)' or 'onException(Error)' call.
 40      * For best results, address should be a comma delineated list of street, suite #, city-state-zip or just zip fields.
 41      * It's less confusing to the geocoder if the person or business name is excluded.
 42      * @param {String} comma delineated address.
 43 	 * @type void
 44 	 */
 45 	findLatLng: function(address) {
 46 		var geo = this;
 47         
 48         geo.geocoder.getLocations(
 49         	address,
 50         	function(response) {
 51         		if (!response) {
 52 					var err = new Error("Unable to convert address to location: "+address);
 53 			        geo._broadcaster.dispatch("onException", {msg: err});
 54 	            } else {
 55 	        		place = response.Placemark[0];
 56 			        point = new GLatLng(place.Point.coordinates[1],
 57 			                            place.Point.coordinates[0]);
 58 
 59 					// address is the input string.  AddressDetails is a hash containing the structured address.
 60 					// See http://www.google.com/apis/maps/documentation/#Geocoding_Structured
 61 			        var latLng = new Garmin.WayPoint(point.lat(), point.lng(), null, address, place.AddressDetails);
 62 			        
 63 			        geo._broadcaster.dispatch("onFinishedFindLatLon", {waypoint: latLng});
 64 	            }
 65         	}
 66         );
 67 	},
 68 	
 69 	/** Register to be an event listener.  An object that is registered will be dispatched
 70      * a method if they have a function with the same dispatch name.  So if you register a
 71      * listener with an onFinishFindDevices, and the onFinishFindDevices message is called, you'll
 72      * get that message.  See class comments for event types
 73      *
 74      * @param {Object} Object that will listen for events coming from this object 
 75      * @see {Garmin.Broadcaster}
 76      */	
 77 	register: function(listener) {
 78         this._broadcaster.register(listener);
 79 	}
 80 
 81 };