package utils
{
import com.google.maps.InfoWindowOptions;
import com.google.maps.Map3D;
import com.google.maps.MapMouseEvent;
import com.google.maps.overlays.Marker;
import com.google.maps.services.ClientGeocoder;
import com.google.maps.services.GeocodingEvent;
import com.google.maps.services.GeocodingResponse;
import com.google.maps.services.Placemark;
import mx.controls.Alert;
public class SearchLocationUtil
{
private var map3DRef:Map3D;
public function SearchLocationUtil()
{
}
/**
* This method locates the searched place in the Map
*/
public function getLocation(mapRef:Map3D, geocoderRef:ClientGeocoder, textClear:String):void
{
this.map3DRef = mapRef;
if(textClear == "")
{
Alert.show("Unable to Find Location");
}
else
{
geocoderRef.addEventListener(GeocodingEvent.GEOCODING_SUCCESS,searchSuccess);
geocoderRef.geocode(textClear);
textClear = "";
}
}
/**
* This method will be executed when it succeeds to search the location on the map
* @Event evt This is the GeocodingEvent
*/
private function searchSuccess(evt:GeocodingEvent):void
{
var placemark:Placemark = GeocodingResponse(evt.response).placemarks[0];
var locateMarker:Marker = new Marker(placemark.point);
locateMarker.addEventListener(MapMouseEvent.ROLL_OVER, function (event:MapMouseEvent):void
{
locateMarker.openInfoWindow(new InfoWindowOptions({contentHTML: "<b>" + placemark.address}));
});
locateMarker.addEventListener(MapMouseEvent.ROLL_OUT, function (event:MapMouseEvent):void
{
locateMarker.closeInfoWindow();
});
this.map3DRef.addOverlay(locateMarker);
}
}
}
No comments:
Post a Comment