001 package com.google.gwt.maps.client.services;
002
003 import com.google.gwt.core.client.JavaScriptObject;
004 import com.google.gwt.core.client.JsArray;
005
006 /**
007 * A service for converting between an address and LatLng.
008 */
009 public class Geocoder extends JavaScriptObject {
010
011 /**
012 * use newInstance();
013 */
014 protected Geocoder() {}
015
016 /**
017 * Creates a new instance of a Geocoder that sends geocode requests to Google servers.
018 */
019 public static final Geocoder newInstance() {
020 return createJso().cast();
021 }
022
023 private static final native JavaScriptObject createJso() /*-{
024 return new $wnd.google.maps.Geocoder();
025 }-*/;
026
027 /**
028 * Geocode a request.
029 * @param request
030 * @param handler
031 */
032 public final native void geocode(GeocoderRequest request, GeocoderRequestHandler handler) /*-{
033 var callback = function(results, status) {
034 @com.google.gwt.maps.client.services.Geocoder::geocodeImpl(Lcom/google/gwt/core/client/JsArray;Ljava/lang/String;Lcom/google/gwt/maps/client/services/GeocoderRequestHandler;)(results, status, handler);
035 };
036 this.geocode(request, callback);
037 }-*/;
038
039 private static final void geocodeImpl(JsArray<GeocoderResult> results, String status, GeocoderRequestHandler handler) {
040 handler.onCallback(results, GeocoderStatus.fromValue(status));
041 }
042
043 }