2016-08-10 40 views
0

任何人的位置cordinates知道如何使用JavaScript API只所在地共同座標(不與地點名稱或地址)路線使用使用ArcGIS的JavaScript API

我需要找到方向一個實施ArcGIS中顯示兩個點之間的行車路線從當前用戶位置特定點(B點)(A點,我從瀏覽器用戶位置),其中目的地B點的緯度和經度存儲在我的數據庫,,,

請幫助'

回答

0

你可以使用RouteTask來獲得結果。

var routeParams = new RouteParameters(); 
routeParams.stops = new FeatureSet(); 
routeParams.returnRoutes = false; 
routeParams.returnDirections = true; 
routeParams.directionsLengthUnits = Units.MILES; 
routeParams.outSpatialReference = new SpatialReference({ wkid:102100 }); 

如果位置在緯度長,它使用webMercatorUtils

routeParams.stops.features.add(new Graphic(pointA)); 
routeParams.stops.features.add(new Graphic(pointB)); 

,如果你有一個你可以在這裏使用自己的服務URL轉換爲WebMercator。

var routeTask = new RouteTask("http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"); 

routeTask .solve(routeParams, function(result){ 
    //handle route result. 
}, function(err){ 
    //handle error 
}); 

如果您使用Directions dijit,它已經有方法來添加點幾何。 https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#addstop

希望這有幫助。

+0

@T Kambi感謝您的回覆..在我的案例中,Directions dijit更合適,我想我正在使用它。我也提到了addStop方法文檔,它看起來不錯。但它不適合我... –

+0

@ Jithin-kuriakose你是否收到任何錯誤信息? –