2012-12-16 105 views
1

我试图在谷歌的MapView上绘制路线。但我行不drawed,在街道上像这样的屏幕截图MapView:在路线上划线

Example image

我用这个代码:

GeoPoint gp1; 
    GeoPoint gp2 = null; 
    StringBuilder sb = new StringBuilder(); 
     sb.append("http://maps.google.com/maps/api/directions/xml").append("?origin=").append(origin) 
     .append("&destination=").append(destination) 
     .append("&mode=driving&sensor=true&language=de"); 
    System.out.println(sb.toString()); 
    xmlPaser parser = new xmlPaser(); 
    String xml = parser.getXmlFromUrl(sb.toString()); 
    Document doc = parser.XmlFromString(xml); 
    System.out.println(doc); 
    NodeList start = doc.getElementsByTagName("start_location"); 
    NodeList end = doc.getElementsByTagName("end_location"); 
    for (int intLoop = 0 ; intLoop < start.getLength() ; intLoop++){ 
     Element eStart = (Element) start.item(intLoop); 
     Element eEnd = (Element) end.item(intLoop); 
     String test = parser.getValue(eStart, "lat"); 
     String test2 = parser.getValue(eStart, "lng"); 
     if (intLoop == 0){ 
      gp1 = new GeoPoint((int) (Double.parseDouble(parser.getValue(eStart, "lat")) * 1E6),(int) (Double.parseDouble(parser.getValue(eStart, "lng")) * 1E6)); 
     }else{ 
      gp1 = gp2; 
     } 
     gp2 = new GeoPoint((int) (Double.parseDouble(parser.getValue(eEnd, "lat")) * 1E6),(int) (Double.parseDouble(parser.getValue(eEnd, "lng")) * 1E6)); 
     ViewMap.getMap().getOverlays().add(new DirectionPathOverlay(gp1, gp2)); 
    } 
} 

怎样绘制在街道上覆盖的线路? 谢谢

回答

0

我已经解决了这个问题。 如果其他人有同样的问题,我会发布这个答案。

start-& end_location只是路线的要点。绘制一个详细的路线视图,你必须使用从XML中解析这个geoPoint。

做到这一点我用这个功能:polyline to geoPoints

,那么你必须在geoPoints传递给你画法。

问候。