如何在谷歌地图上绘制两个位置之间的折线(知道纬度/经度)?

时间:2011-02-17 12:52:04

标签: iphone google-maps


我有这个信息,当我点击谷歌方向API时我得到。我知道如何解析它。但我不知道如何使用这些信息在两个地方之间绘制折线。请告诉我你的任何想法。

<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>a~l~Fjk~uOwHJy@P</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>a~l~Fjk~uOnzh@vlbBtc~@tsE`vnApw{A`dw@~w\|tNtqf@l{Yd_Fblh@rxo@b}@xxSfytAblk@xxaBeJxlcBb~t@zbh@jc|Bx}C`rv@rw|@rlhA~dVzeo@vrSnc}Axf]fjz@xfFbw~@dz{A~d{A|zOxbrBbdUvpo@`cFp~xBc`Hk@nurDznmFfwMbwz@bbl@lq~@loPpxq@bw_@v|{CbtY~jGqeMb{iF|n\~mbDzeVh_Wr|Efc\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg@|kHntyArpb@bijCk_Kv~eGyqTj_|@`uV`k|DcsNdwxAott@r}q@_gc@nu`CnvHx`k@dse@j|p@zpiAp|gEicy@`omFvaErfo@igQxnlApqGze~AsyRzrjAb__@ftyB}pIlo_BflmA~yQftNboWzoAlzp@mz`@|}_@fda@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>

1 个答案:

答案 0 :(得分:0)

假设您使用的是iOS 4,那么您将使用MKMapView和MKOverlay。 MKOverlay允许您为要在地图上绘制的内容指定边界框;当需要图形时,将要求MKMapViewDelegate提供MKOverlayView来绘制实际内容。绘制折线特别容易,因为您可以传回内置MKOverlayPathView的实例。

而不是我试图提出示例代码,最简单的方法是look at Apple's KMLViewer example(其中KML方面很容易阅读过去)。