2012-12-16 294 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傳遞給你畫法。

問候。