iOS應用內跳轉百度高德蘋果地圖

來源:互聯網
上載者:User

標籤:tar   安裝   依賴性   cli   ios應用   ios   class   open   current   

移動開發經常用到基於位置的一些導航功能,但是對於對導航功能依賴性不強的的應用,我們直接採用應用外跳轉地圖APP即可。

但是應用間跳轉,首先需要設定白名單,

在iOS 9 下涉及到平台用戶端跳轉,系統會自動到項目info.plist下檢測是否設定平台Scheme,對於需要配置的平台,如果沒有配置,將無法正常跳轉平台用戶端,因此需要配置Scheme名單。本文我們需要添加百度地圖和高德地圖的scheme白名單。

具體方法:在項目的info.plist中添加LSApplicationQueriesSchemes欄位,類型是Array,然後添加兩個Item。

下面直接上主要代碼,網上高德都是直接導航的,為啥?都那麼做?

- (void)mapBtnclick{   if (![NSString isNotEmptyString:_currentadress]) {       [self.locationManager startUpdatingLocation];       [SDIndicator showInfoWithMessage:@"正在定位,請稍候..."];   }   _actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];   NSMutableArray *mapsArray=[[NSMutableArray alloc] initWithCapacity:0];   _mapsUrlArray=[[NSMutableArray alloc] init];   NSURL * apple_App = [NSURL URLWithString:@"http://maps.apple.com/"];   if ([[UIApplication sharedApplication] canOpenURL:apple_App]) {       [mapsArray addObject:@"使用蘋果內建地圖導航"];       NSString *urlString=[NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",_strLatitude,_strLongitude,[_model.last_latitude floatValue],[_model.last_longitude floatValue] ];       [_mapsUrlArray addObject:urlString];   }      NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];   if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {       [mapsArray addObject:@"使用百度地圖導航"];              NSString *stringURL =[[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];       [_mapsUrlArray addObject:stringURL];          }      NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];   if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {       [mapsArray addObject:@"使用高德地圖導航"];       NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=%f&slon=%f&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&t=0",@"龍巔魚鄰",_strLatitude,_strLongitude,_currentadress,[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];       [_mapsUrlArray addObject:urlString];          }      for (int x=0; x<mapsArray.count; x++) {       [_actionSheet addButtonWithTitle:[mapsArray objectAtIndex:x]];          }      if (_mapsUrlArray.count>0) {        [_actionSheet showInView:self.view.window];   }else{       [SDIndicator showInfoWithMessage:@"建議您安裝高德或者百度地圖"];   }  }

 下面說一下,主要的知識點

【1】

使用canOpenURL方法來檢測該手機是否安裝相應APP

該方法會返回一個BOOL值,當為YES時,表明已安裝該APP

 

【2】

1、蘋果內建地圖(不需要檢測,所以不需要URL Scheme)
2、百度地圖 baidumap://
3、高德地圖 iosamap://

 

當然要攜帶參數的話,就按照各個地圖的規則進行傳值即可

 

iOS應用內跳轉百度高德蘋果地圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.