項目裏面有位置功能,須要有導航,導航兩種實現方式 (集成第三方SDK、URL跳轉第三方應用) ,直接集成就不說,下面來講下經過url跳轉,php
最終效果如以下:html
若是手機上安裝的有客戶端就展現,沒有就不展現,文檔上面寫的很詳細的,具體地址以下:ios
高德地圖:https://lbs.amap.com/api/amap-mobile/guide/ios/navigit
百度地圖:http://lbsyun.baidu.com/index.php?title=uri/api/iosweb
騰訊地圖:http://lbs.qq.com/uri_v1/guide-mobile-navAndRoute.htmlapi
國內用的暫時就這些,不過須要注意的是,騰訊地圖有一個參數須要註冊平臺開發者帳號才能使用,參數仍是必傳的,以下圖:app
具體實現代碼以下:webapp
1、添加白名單ide
2、具體實現代碼以下:ui
-(void)getOpenURL { [self getInstalledMapAppWithEndLocation:destinationCoordinate2D]; for (int i = 0; i < self.maps.count; i ++) { NSString *title = [NSString stringWithFormat:@"%@",self.maps[i][@"title"]]; [_titleMaps addObject:title]; } }
#pragma mark 一鍵導航 - (IBAction)navigationAction:(id)sender { // 實例方法 LCActionSheet *sheet = [[LCActionSheet alloc] initWithTitle:@"請選擇地圖" buttonTitles:_titleMaps redButtonIndex:-1 delegate:self]; [sheet show]; } -(void)actionSheet:(LCActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != -1) { if (buttonIndex == 0) { [self navAppleMap]; return; } NSDictionary *dic = self.maps[buttonIndex]; NSString *urlString = dic[@"url"]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; } } //蘋果地圖 - (void)navAppleMap { CLLocationCoordinate2D gps = [JZLocationConverter bd09ToWgs84:destinationCoordinate2D]; MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation]; MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:gps addressDictionary:nil]]; NSArray *items = @[currentLoc,toLocation]; NSDictionary *dic = @{ MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard), MKLaunchOptionsShowsTrafficKey : @(YES) }; [MKMapItem openMapsWithItems:items launchOptions:dic]; } #pragma mark - 導航方法 - (NSArray *)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)endLocation { //蘋果地圖 NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary]; iosMapDic[@"title"] = @"蘋果地圖"; [self.maps addObject:iosMapDic]; //百度地圖 if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) { NSMutableDictionary *baiduMapDic = [NSMutableDictionary dictionary]; baiduMapDic[@"title"] = @"百度地圖"; NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=個人位置&destination=%f,%f&mode=driving&src=webapp.navi.yourCompanyName.yourAppName",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; baiduMapDic[@"url"] = urlString; [self.maps addObject:baiduMapDic]; } //高德地圖 if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) { NSMutableDictionary *gaodeMapDic = [NSMutableDictionary dictionary]; gaodeMapDic[@"title"] = @"高德地圖"; NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=applicationName&poiname=fangheng&poiid=BGVIS&lat=%f&lon=%f&dev=1&style=2",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; gaodeMapDic[@"url"] = urlString; [self.maps addObject:gaodeMapDic]; } //騰訊地圖 if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) { NSMutableDictionary *qqMapDic = [NSMutableDictionary dictionary]; qqMapDic[@"title"] = @"騰訊地圖"; NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=個人位置&to=洗車點&tocoord=%f,%f&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; qqMapDic[@"url"] = urlString; [self.maps addObject:qqMapDic]; } return self.maps; }
而後直接調用getOpenURL方法便可,傳經緯度是用CLLocationCoordinate2D直接傳的,展現用的是大神寫好的第三方庫:LCActionSheet,上面的代碼能夠直接使用,親測有效!若是變更,請以文檔爲準!