我从arcgis下载了一个名为RoutingSample的项目,然后我尝试在我的日食中使用它。 它在我的平板电脑上运行没有错误,但当它到达命令" RouteTask.solve(rp);"它会引发异常,因此无法计算路线:
' com.esri.core.io.EsriServiceException:无法完成操作。
位置"位置1" in" Stops"是不定位的。位置"位置2" in" Stops"是>未定位的。 至少需要2个有效站点 "停止"不包含任何路线的有效输入。'
任何想法?
这是我的位置:
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;
答案 0 :(得分:0)
我有同样的例外,解决方案是审查服务和应用程序的SpatialReference,在两者中使用相同,如果服务有不同的SpatialReference,那么你将找不到位置。 例如,用于GPS 4326。
我希望它有所帮助。
示例:
如果您在
处声明SpatialReferenceprivate SpatialReference wm,egs;
......
wm = SpatialReference.create(102100);
egs = SpatialReference.create(4326);
然后确保您的MapService SpatialReference是:
Spatial Reference: 102100 (4326)
(如果您在路由示例https://developers.arcgis.com/android/sample-code/routing/中使用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);
它适用于我。