因此,自 2012 年 7 月 21 日以来,我听说不可能再使用 KLM 在 2 个 GeoPoint 之间绘制路径,我遵循了这个:
为什么使用 KML 数据检索适用于 Android 的 Google 路线不再有效?
但我得到一个错误,这里是我的活动中的 onCreate() 方法:
Route route = directions(new GeoPoint((int)(26.2*1E6),(int)(50.6*1E6)), new GeoPoint((int)(26.3*1E6),(int)(50.7*1E6)));
RouteOverlay routeOverlay = new RouteOverlay(route, Color.BLUE);
mapView.getOverlays().add(routeOverlay);
mapView.invalidate();
Activity 中调用的方法:
private Route directions(final GeoPoint start, final GeoPoint dest) {
//Changed from Parser to GoogleParser beacause i had Error
GoogleParser parser;
//https://developers.google.com/maps/documentation/directions/#JSON <- get api
String jsonURL = "http://maps.googleapis.com/maps/api/directions/json?";
final StringBuffer sBuf = new StringBuffer(jsonURL);
sBuf.append("origin=");
sBuf.append(start.getLatitudeE6()/1E6);
sBuf.append(',');
sBuf.append(start.getLongitudeE6()/1E6);
sBuf.append("&destination=");
sBuf.append(dest.getLatitudeE6()/1E6);
sBuf.append(',');
sBuf.append(dest.getLongitudeE6()/1E6);
sBuf.append("&sensor=true&mode=driving");
parser = new GoogleParser(sBuf.toString());
Route r = parser.parse();
return r;
}
日志输出:
11-23 16:07:50.126: E/AndroidRuntime(24124): FATAL EXCEPTION: main
11-23 16:07:50.126: E/AndroidRuntime(24124): java.util.NoSuchElementException
11-23 16:07:50.126: E/AndroidRuntime(24124): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:572)
11-23 16:07:50.126: E/AndroidRuntime(24124): at com.xxx.xxx.xxx.RouteOverlay.redrawPath(RouteOverlay.java:90)
11-23 16:07:50.126: E/AndroidRuntime(24124): at com.xxx.xxx.xxx.RouteOverlay.draw(RouteOverlay.java:60)
11-23 16:07:50.126: E/AndroidRuntime(24124): at com.google.android.maps.Overlay.draw(Overlay.java:179)
11-23 16:07:50.126: E/AndroidRuntime(24124): at
ETC ...
线路错误(RouteOverlay.java):
prj.toPixels(it.next(), p);
上 :
private void redrawPath(final MapView mv) {
final Projection prj = mv.getProjection();
path.rewind();
final Iterator<GeoPoint> it = routePoints.iterator();
//Crash Here
prj.toPixels(it.next(), p);
path.moveTo(p.x, p.y);
while (it.hasNext()) {
prj.toPixels(it.next(), p);
path.lineTo(p.x, p.y);
}
path.setLastPoint(p.x, p.y);
}
谢谢 。