在ios6中调用苹果地图用于导航

os6以下我们一般用google地图来导航,但ios6中调用会有点问题,会打开web浏览器再询问之类的,不直观友好。所以在ios6中建议直接用apple map。本来调用apple map应该和调用google map类似,但使用:

http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f 会提示无法定位,不知道为什么?

使用maps://saddr=%f,%f&daddr=%f,%f 会找不到当前位置,也不清楚原因?

不过还是找到了解决方法,如下(包括两种地图调用方式):

<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln" style="color: rgb(0, 0, 0);">SYSTEM_VERSION_LESS_THAN</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pun" style="color: rgb(102, 102, 0);">@</span><span class="str" style="color: rgb(0, 136, 0);">"6.0"</span><span class="pun" style="color: rgb(102, 102, 0);">))</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="com" style="color: rgb(136, 0, 0);">// ios6</span><span class="com" style="color: rgb(136, 0, 0);">以下,调用google map</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="typ" style="color: rgb(102, 0, 102);">NSString</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln" style="color: rgb(0, 0, 0);">urlString </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">[[</span><span class="typ" style="color: rgb(102, 0, 102);">NSString</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">alloc</span><span class="pun" style="color: rgb(102, 102, 0);">]</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">                        </span><span class="pln" style="color: rgb(0, 0, 0);">initWithFormat</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pun" style="color: rgb(102, 102, 0);">@</span><span class="str" style="color: rgb(0, 136, 0);">"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d"</span><span class="pun" style="color: rgb(102, 102, 0);">,</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">                        </span><span class="pln" style="color: rgb(0, 0, 0);">cutLat</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);">cutLon</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);">stationLat</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);">stationLon</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="pln" style="color: rgb(0, 0, 0);">NSURL</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln" style="color: rgb(0, 0, 0);">aURL </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln" style="color: rgb(0, 0, 0);">NSURL</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">URLWithString</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">urlString</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln" style="color: rgb(0, 0, 0);">urlString </span><span class="pln" style="color: rgb(0, 0, 0);">release</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="pun" style="color: rgb(102, 102, 0);">[[</span><span class="typ" style="color: rgb(102, 0, 102);">UIApplication</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">sharedApplication</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">openURL</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">aURL</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="kwd" style="color: rgb(0, 0, 136);">else</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="com" style="color: rgb(136, 0, 0);">// </span><span class="com" style="color: rgb(136, 0, 0);">直接调用</span><span class="com" style="color: rgb(136, 0, 0);">ios</span><span class="com" style="color: rgb(136, 0, 0);">自己带的</span><span class="com" style="color: rgb(136, 0, 0);">apple map</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="typ" style="color: rgb(102, 0, 102);">CLLocationCoordinate2D</span><span class="pln" style="color: rgb(0, 0, 0);"> to</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            to</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">latitude</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">stationLat</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            to</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">longitude</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">stationLon</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="typ" style="color: rgb(102, 0, 102);">MKMapItem</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln" style="color: rgb(0, 0, 0);">currentLocation </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="typ" style="color: rgb(102, 0, 102);">MKMapItem</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">mapItemForCurrentLocation</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="typ" style="color: rgb(102, 0, 102);">MKMapItem</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln" style="color: rgb(0, 0, 0);">toLocation </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">[[</span><span class="typ" style="color: rgb(102, 0, 102);">MKMapItem</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">alloc</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">initWithPlacemark</span><span class="pun" style="color: rgb(102, 102, 0);">:[[[</span><span class="typ" style="color: rgb(102, 0, 102);">MKPlacemark</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">alloc</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">initWithCoordinate</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">to </span><span class="pln" style="color: rgb(0, 0, 0);">addressDictionary</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="kwd" style="color: rgb(0, 0, 136);">nil</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">autorelease</span><span class="pun" style="color: rgb(102, 102, 0);">]];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            toLocation</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">name</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">@</span><span class="str" style="color: rgb(0, 136, 0);">"Destination"</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="typ" style="color: rgb(102, 0, 102);">MKMapItem</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">openMapsWithItems</span><span class="pun" style="color: rgb(102, 102, 0);">:[</span><span class="typ" style="color: rgb(102, 0, 102);">NSArray</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">arrayWithObjects</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">currentLocation</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);"> toLocation</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="kwd" style="color: rgb(0, 0, 136);">nil</span><span class="pun" style="color: rgb(102, 102, 0);">]</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">                           </span><span class="pln" style="color: rgb(0, 0, 0);">launchOptions</span><span class="pun" style="color: rgb(102, 102, 0);">:[</span><span class="typ" style="color: rgb(102, 0, 102);">NSDictionary</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">dictionaryWithObjects</span><span class="pun" style="color: rgb(102, 102, 0);">:[</span><span class="typ" style="color: rgb(102, 0, 102);">NSArray</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">arrayWithObjects</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="typ" style="color: rgb(102, 0, 102);">MKLaunchOptionsDirectionsModeDriving</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="typ" style="color: rgb(102, 0, 102);">NSNumber</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">numberWithBool</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">YES</span><span class="pun" style="color: rgb(102, 102, 0);">],</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="kwd" style="color: rgb(0, 0, 136);">nil</span><span class="pun" style="color: rgb(102, 102, 0);">]</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">                                                                     </span><span class="pln" style="color: rgb(0, 0, 0);">forKeys</span><span class="pun" style="color: rgb(102, 102, 0);">:[</span><span class="typ" style="color: rgb(102, 0, 102);">NSArray</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pln" style="color: rgb(0, 0, 0);">arrayWithObjects</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="typ" style="color: rgb(102, 0, 102);">MKLaunchOptionsDirectionsModeKey</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">MKLaunchOptionsShowsTrafficKey</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="kwd" style="color: rgb(0, 0, 136);">nil</span><span class="pun" style="color: rgb(102, 102, 0);">]]];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">            </span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln" style="color: rgb(0, 0, 0);">toLocation </span><span class="pln" style="color: rgb(0, 0, 0);">release</span><span class="pun" style="color: rgb(102, 102, 0);">];</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln" style="color: rgb(0, 0, 0);">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></p>
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
记得加上:

<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="com" style="color: rgb(136, 0, 0);">#define</span><span class="pln" style="color: rgb(0, 0, 0);"> SYSTEM_VERSION_LESS_THAN</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln" style="color: rgb(0, 0, 0);">v</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">([[[</span><span class="typ" style="color: rgb(102, 0, 102);">UIDevice</span><span class="pln" style="color: rgb(0, 0, 0);"> currentDevice</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> systemVersion</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> compare</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">v options</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="typ" style="color: rgb(102, 0, 102);">NSNumericSearch</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">NSOrderedAscending</span><span class="pun" style="color: rgb(102, 102, 0);">)</span></p>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值