001 package com.google.gwt.maps.client.services;
002
003 import com.google.gwt.core.client.JavaScriptObject;
004 import com.google.gwt.maps.client.workaround.WorkAroundUtils;
005
006 /**
007 * A service for computing distances between multiple origins and destinations.
008 * <br><br>
009 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#DistanceMatrixService">DistanceMatrixService API Doc</a>
010 */
011 public class DistanceMatrixService extends JavaScriptObject {
012
013 /**
014 * use newInstance();
015 */
016 protected DistanceMatrixService() {}
017
018 /**
019 * Creates a new instance of a DistanceMatrixService that sends distance matrix queries to Google servers.
020 */
021 public static final DistanceMatrixService newInstance() {
022 JavaScriptObject jso = createJso();
023 WorkAroundUtils.removeGwtObjectId(jso);
024 return jso.cast();
025 }
026
027 private static final native JavaScriptObject createJso() /*-{
028 return new $wnd.google.maps.DistanceMatrixService();
029 }-*/;
030
031 public final native void getDistanceMatrix(DistanceMatrixRequest request, DistanceMatrixRequestHandler handler) /*-{
032 var callback = function(response, status) {
033 @com.google.gwt.maps.client.services.DistanceMatrixService::getDistanceMatrixImpl(Lcom/google/gwt/maps/client/services/DistanceMatrixResponse;Ljava/lang/String;Lcom/google/gwt/maps/client/services/DistanceMatrixRequestHandler;)(response, status, handler);
034 };
035 this.getDistanceMatrix(request, callback);
036 }-*/;
037
038 private static final void getDistanceMatrixImpl(DistanceMatrixResponse response, String status, DistanceMatrixRequestHandler handler) {
039 handler.onCallback(response, DistanceMatrixStatus.fromValue(status));
040 }
041
042 }