All pastes #970063 Raw Edit

searchAddress method

public javascript v1 · immutable
·published 2008-04-03 20:34 UTC
rendered paste body
searchAddress: function (address, settings, callback) {		var settings = jQuery.extend({			returntype: "map"	//Return as Map or a Object		},settings);		var jmap = this[0].jMap;		// Yahoo Maps		if (jmap._mapType) {			jmap.geoCodeAddress(address);			YEvent.Capture(jmap, EventsList.onEndGeoCode, function(e){				if(e.success == 0) {					alert(address + " not found");				} else {					switch (settings.returntype) {						case "object":							var results = [];							results[0] = e.GeoPoint.Lat;							results[1] = e.GeoPoint.Lon;							callback(results);							break;						default:							point = new YGeoPoint(e.GeoPoint.Lat,e.GeoPoint.Lon);							jmap.drawZoomAndCenter(point);							var marker = new YMarker(point);	// Create the Yahoo marker type							marker.openSmartWindow("Latitude: " + point.Lat + "<br />Longitude: " + point.Lon);							jmap.addOverlay(marker);	// Add marker to map							break;					}				}			});			//Google Maps		} else if (jmap.b.jMap) {			GGeocoder = new GClientGeocoder();			GGeocoder.getLatLng(address, function(point){				if (!point) {					alert(address + " not found");				} else {					switch (settings.returntype) {						case "object":							var results = [];							results[0] = point.y;							results[1] = point.x;													callback(results);							break;						default:							jmap.setCenter(point);							var marker = new GMarker(point, {draggable: true});							jmap.addOverlay(marker);							var pointlocation = marker.getPoint();							marker.openInfoWindowHtml("Latitude: " + pointlocation.lat() + "<br />Longitude: " + pointlocation.lng());							GEvent.addListener(marker, "dragend", function(pointlocation){								marker.openInfoWindowHtml("Latitude: " + pointlocation.lat() + "<br />Longitude: " + pointlocation.lng());										});							break;					}				}			});		} else {			alert('Map Object Not Found!');		}	}