开发者

How to draw polyline between two locations (knowing latitude/longitude) on Google map?

I have this Information which i get when i hit google Direction api. I know how to parse it. But i don't know how to use this inf开发者_C百科ormation to draw polyline between two places. Please give me any of your idea.

<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>


Assuming you're on iOS 4, you'd use an MKMapView and an MKOverlay. The MKOverlay allows you to specify a bounding box for the thing you're trying to draw on the map; as and when the graphic is required your MKMapViewDelegate will be asked to supply an MKOverlayView to draw the actual content. Drawing a polyline is particularly easy because you can pass back an instance of the built-in MKOverlayPathView.

Rather than me trying to come up with example code, the easiest thing to do is to look at Apple's KMLViewer example (the KML aspect of which is pretty easy to read past).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜