从我的位置到arcgis for android中定义的点的路由
我从arcgis下载了一个名为RoutingSample的项目,然后我尝试在eclipse上使用它。 它在我的平板电脑上运行没有错误,但是当它到达RouteTask.solverp命令时;它引发异常,因此无法计算路由: 'com.esri.core.io.EsriServiceException:无法完成操作 站点中的位置1未定位。站点中的位置2>未定位。 至少需要2个有效站点。 站点不包含任何路由的有效输入。' 有什么想法吗 这是我的第一个位置:从我的位置到arcgis for android中定义的点的路由,android,routing,maps,arcgis,mmap,Android,Routing,Maps,Arcgis,Mmap,我从arcgis下载了一个名为RoutingSample的项目,然后我尝试在eclipse上使用它。 它在我的平板电脑上运行没有错误,但是当它到达RouteTask.solverp命令时;它引发异常,因此无法计算路由: 'com.esri.core.io.EsriServiceException:无法完成操作 站点中的位置1未定位。站点中的位置2>未定位。 至少需要2个有效站点。 站点不包含任何路由的有效输入。' 有什么想法吗 这是我的第一个位置: public void onLocationC
public void onLocationChanged(Location loc) {
if (loc == null)
return;
boolean zoomToMe = (mLocation == null) ? true : false;
mLocation = new Point(loc.getLongitude(), loc.getLatitude());
if (zoomToMe) {
// Point mapPoint = (Point) GeometryEngine.project(mLocation, SpatialReference.create(4326), map.getSpatialReference());
Point p = (Point) GeometryEngine.project(mLocation, egs, wm);
map.zoomToResolution(p, 20.0);
}
}
这是我计算路由的长pess侦听器:
// Clear the graphics and empty the directions list
routeLayer.removeAll();
hiddenSegmentsLayer.removeAll();
curDirections = new ArrayList<String>();
mResults = null;
// retrieve the user clicked location
final Point loc = map.toMapPoint(x, y);
// Show that the route is calculating
dialog = ProgressDialog.show(RoutingSample.this, "",
"Calculating route...", true);
// Spawn the request off in a new thread to keep UI responsive
Thread t = new Thread() {
@Override
public void run() {
try {
// Start building up routing parameters
RouteParameters rp = mRouteTask
.retrieveDefaultRouteTaskParameters();
NAFeaturesAsFeature rfaf = new NAFeaturesAsFeature();
// Convert point to EGS (decimal degrees)
Point p = (Point) GeometryEngine.project(loc, wm,
egs);
// Create the stop points (start at our location, go
// to pressed location)
StopGraphic point1 = new StopGraphic(mLocation);
StopGraphic point2 = new StopGraphic(p);
rfaf.setFeatures(new Graphic[] { point1, point2 });
rfaf.setCompressedRequest(true);
rp.setStops(rfaf);
// Set the routing service output SR to our map
// service's SR
rp.setOutSpatialReference(wm);
// Solve the route and use the results to update UI
// when received
mResults = mRouteTask.solve(rp);
mHandler.post(mUpdateResults);
} catch (Exception e) {
mException = e;
mHandler.post(mUpdateResults);
}
}
};
// Start the operation
t.start();
return true;
我也有同样的例外,解决方案是查看服务和应用程序的空间引用,在两者中使用相同的方法,如果服务有不同的空间引用,那么您将找不到位置。 例如,用于GPS 4326 我希望有帮助 例如: 如果您在
private SpatialReference wm,egs;
......
wm = SpatialReference.create(102100);
egs = SpatialReference.create(4326);
然后确保您的MapService SpatialReference是:
Spatial Reference: 102100 (4326)
如果在路由示例中使用Esri MapService和NAService服务,则无需担心这一点
现在,您可以在onLongPressListener中转换屏幕点
Point loc = map.toMapPoint(x, y);
Point p = (Point) GeometryEngine.project(loc, wm, egs);
/*initialize RouteTask*/
RouteTask rt = RouteTask.createOnlineRouteTask("your service url",null);
RouteParameters rp = rt.retrieveDefaultRouteTaskParameters();
NAFeaturesAsFeature rfaf = new NAFeaturesAsFeature();
//mlocation is your latitude and longitude point provided by GPS location in decimal degrees
StopGraphic point1 = new StopGraphic(mlocation);
StopGraphic point2 = new StopGraphic(p);
rfaf.setFeatures(new Graphic[]{point1,point2});
rfaf.setCompressedRequest(true);
rp.setStops(rfaf);
rp.setOutSpatialReference(wm);
RouteResult mresults = rt.solve(rp);
这对我来说很好。我也面临同样的例外,但我对Esri地图还不熟悉,所以请您向我解释一下答案