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 directions between two or more places.
008 * <br><br>
009 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#DirectionsService">DirectionsService API Doc</a>
010 */
011 public class DirectionsService extends JavaScriptObject {
012
013 /**
014 * use newInstance();
015 */
016 protected DirectionsService() {}
017
018 /**
019 * Creates a new instance of a DirectionsService that sends directions queries to Google servers.
020 */
021 public static final DirectionsService 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.DirectionsService();
029 }-*/;
030
031 /**
032 * Issue a directions search request.
033 *
034 * TODO I can't test this in dev mode, but seems to be working in production deployed. maps api can't find <__gwt_ObjectId>
035 *
036 * @param request
037 * @param handler
038 */
039 public final native void route(DirectionsRequest request, DirectionsResultHandler handler) /*-{
040 var callback = function(result, status) {
041
042 // debug
043 //@com.google.gwt.maps.client.services.DirectionsService::test(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)("result=", result);
044 //@com.google.gwt.maps.client.services.DirectionsService::test(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)("status=", status);
045
046 // process callback
047 @com.google.gwt.maps.client.services.DirectionsService::routeImpl(Lcom/google/gwt/maps/client/services/DirectionsResult;Ljava/lang/String;Lcom/google/gwt/maps/client/services/DirectionsResultHandler;)(result, status, handler);
048 };
049
050 // // this works - but the incoming request2 jso, matches exactly yet, won't work, ????
051 // var request2 = {
052 // origin: "Arlington, WA",
053 // destination: "Seattle, WA",
054 // travelMode: "DRIVING" // or is $wnd.google.maps.TravelMode.DRIVING
055 // };
056
057 // output the object for debugging
058 //@com.google.gwt.maps.client.services.DirectionsService::test(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)("request", request);
059 //@com.google.gwt.maps.client.services.DirectionsService::test(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)("request2=", request2);
060
061 this.route(request, callback);
062 }-*/;
063
064 private static final void routeImpl(DirectionsResult result, String status, DirectionsResultHandler handler) {
065 handler.onCallback(result, DirectionsStatus.fromValue(status));
066 }
067
068 // public static final void test(String msg, JavaScriptObject jso) {
069 // JSONObject j = new JSONObject(jso);
070 // GWT.log("msg= "+ msg + " jso=" + j.toString());
071 // }
072 //
073
074 }