2011-02-17 36 views
1


我有這方面的信息,當我打google方向api時得到的。我知道如何解析它。但我不知道如何使用這些信息在兩個地方之間繪製折線。請給我任何想法。如何在Google地圖上的兩個位置之間繪製折線(知道經度/緯度)?

<DirectionsResponse> 
<status>OK</status> 
<route> 
    <summary>I-40 W</summary> 
    <leg> 
    <step> 
    <travel_mode>DRIVING</travel_mode> 
    <start_location> 
    <lat>41.8507300</lat> 
    <lng>-87.6512600</lng> 
    </start_location> 
    <end_location> 
    <lat>41.8525800</lat> 
    <lng>-87.6514100</lng> 
    </end_location> 
    <polyline> 
    <points>[email protected]</points> 
    <levels>B?B</levels> 
    </polyline> 
    <duration> 
    <value>19</value> 
    <text>1 min</text> 
    </duration> 
    <html_instructions>Head <b>north</b> on <b>S Morgan St</b> toward <b>W Cermak Rd</b></html_instructions> 
    <distance> 
    <value>207</value> 
    <text>0.1 mi</text> 
    </distance> 
    </step> 
    ... 
    ... additional steps of this leg 
    ... 
    ... additional legs of this route 
    <duration> 
    <value>74384</value> 
    <text>20 hours 40 mins</text> 
    </duration> 
    <distance> 
    <value>2137146</value> 
    <text>1,328 mi</text> 
    </distance> 
    <start_location> 
    <lat>35.4675602</lat> 
    <lng>-97.5164276</lng> 
    </start_location> 
    <end_location> 
    <lat>34.0522342</lat> 
    <lng>-118.2436849</lng> 
    </end_location> 
    <start_address>Oklahoma City, OK, USA</start_address> 
    <end_address>Los Angeles, CA, USA</end_address> 
    <copyrights>Map data ©2010 Google, Sanborn</copyrights> 
    <overview_polyline> 
    <points>[email protected][email protected]`vnApw{A`[email protected]~w\|[email protected]{[email protected]@b}@[email protected][email protected]@jc|Bx}C`[email protected]|@[email protected]}Axf][email protected][email protected]{A~d{A|[email protected]`cFp~xBc`[email protected]@[email protected][email protected]@[email protected]|{CbtY~jGqeMb{iF|n\~mbDzeVh_Wr|Efc\x`Ij{kE}mAb~uF{cNd}xBjp][email protected]|kHnty[email protected]_Kv~eGyqTj_|@`uV`k|[email protected]}[email protected][email protected]`CnvHx`[email protected]@j|[email protected]|[email protected]`[email protected][email protected]}[email protected]`@|}[email protected]@jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC</points> 
    <levels>BBBAAAAABAABAAAAAABBAAABBAAAABBAAABABAAABABBAABAABAAAABABABABBABAABB</levels> 
    </overview_polyline> 
    <optimized_waypoint_index>0</optimized_waypoint_index> 
    <optimized_waypoint_index>1</optimized_waypoint_index> 
    <bounds> 
    <southwest> 
    <lat>34.0523600</lat> 
    <lng>-118.2435600</lng> 
    </southwest> 
    <northeast> 
    <lat>41.8781100</lat> 
    <lng>-87.6297900</lng> 
    </northeast> 
    </bounds> 
</route> 
</DirectionsResponse> 
+0

你在使用MKMapView嗎? – Anna 2011-02-17 13:10:12

回答

0

假設你在iOS 4上,你可以使用MKMapView和MKOverlay。 MKOverlay允許你爲你試圖在地圖上繪製的東西指定一個邊界框;當需要圖形時,你的MKMapViewDelegate會被要求提供一個MKOverlayView來繪製實際的內容。繪製折線非常簡單,因爲您可以傳回內置MKOverlayPathView的實例。

而不是我試圖想出示例代碼,最簡單的事情就是look at Apple's KMLViewer example(KML方面很容易閱讀過去)。

相關問題