我正在尝试在位置之间绘制路径,并在解析KML时遇到错误。执行停止在这里:
InputSource inputSource = new InputSource(url.openStream());
未执行以下行
reader.parse(的InputSource);
private void drawPath(GeoPoint src, GeoPoint dest, MapView mapView) {
String strUrl = "http://maps.google.com/maps?";
//From
strUrl += "saddr=" +
(src.getLatitudeE6()/1.0E6) +
"," +
(src.getLongitudeE6()/1.0E6);
//To
strUrl += "&daddr=" +
(dest.getLatitudeE6()/1.0E6) +
"," +
(dest.getLongitudeE6()/1.0E6);
//Walk attribute (for walk path)
strUrl += "&dirflg=w";
//File format
strUrl += "&output=kml";
try {
//Parse KML
URL url = new URL(strUrl.toString());
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser parser = saxFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
KMLHandler kmlHandler = new KMLHandler();
reader.setContentHandler(kmlHandler);
InputSource inputSource = new InputSource(url.openStream());
reader.parse(inputSource);
String path = kmlHandler.getPathCoordinates();
//Draw path
if(path != null) {
RouteOverlay routeOverlay = new RouteOverlay();
String pairs[] = path.split(" ");
for (String pair : pairs) {
String coordinates[] = pair.split(",");
GeoPoint geoPoint = new GeoPoint(
(int) (Double.parseDouble(coordinates[1]) * 1E6),
(int) (Double.parseDouble(coordinates[0]) * 1E6));
routeOverlay.addGeoPoint(geoPoint);
}
mapView.getOverlays().add(routeOverlay);
}
} catch (Exception e) {
Log.w("RoutePath", e.toString());
}
}