小秀秀終于更新博客啦O冉稀!RK摺拇泣!
過年前,換了一個項目組矮锈,過年來了就變得比之前忙了霉翔,忙著忙著,立了flag學(xué)習(xí)的我苞笨,就這個樣子消失啦,說好的寫博客呢债朵?5月份的我辭職了,6月入職了現(xiàn)在這家公司瀑凝,也算是換了一個工作內(nèi)容吧序芦!之前主要是做企業(yè)項目,現(xiàn)在是做電商粤咪,對我來說還是接觸了很多之前沒有接觸的東西谚中,還是很開心~
一晃又是十月啦,我的博客也該更新咯~~
雖然寫了小筆記寥枝,但是還是被自己弄掉了宪塔,寫在簡書里面,總不會弄掉了囊拜,內(nèi)容會比較潦草某筐,還請各位看官多多包容哦~
APP里面有一個地址,想做一個導(dǎo)航功能冠跷,直接調(diào)起手機里面其他APP的導(dǎo)航南誊,來的比較直接身诺,以下為參考地址,最后封裝成一個類抄囚。
我們APP使用的是騰訊地圖霉赡,我在騰訊開發(fā)平臺沒有找到使用cocoapods集成的方式,只能手動集成怠苔,這一點有些不開心~
比如APP的有些功能是基于定位來推薦的同廉,如果切換到其他地方去呢?參考如下網(wǎng)址進行模擬定位柑司,真的很實用勒~使用Xcode工具模擬定位迫肖,你可以去全世界
三個地圖的官方文檔地址:
我們常說的坐標系有哪些?
WGS84:為一種大地坐標系攒驰,也是目前廣泛使用的GPS全球衛(wèi)星定位系統(tǒng)使用的坐標系蟆湖。
GCJ02:又稱火星坐標系,是由中國國家測繪局制定的地理坐標系統(tǒng)玻粪,是由WGS84加密后得到的坐標系隅津。
BD09:為百度坐標系,在GCJ02坐標系基礎(chǔ)上再次加密劲室。其中bd09ll表示百度經(jīng)緯度坐標伦仍,bd09mc表示百度墨卡托米制坐標。
國外使用WGS84坐標系很洋,國內(nèi)至少使用BD09坐標系
最后將代碼封裝成一個如下的類
+(void)jumpMapsByLat:(NSString *)lat lon:(NSString *)lon address:( NSString *)address{
NSString *appName = [[[NSBundle mainBundle] infoDictionary]objectForKey:@"CFBundleDisplayName"];
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"請選擇地圖" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"使用蘋果自帶地圖導(dǎo)航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//起點
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:[QMDataManager shareManager].location.coordinate addressDictionary:nil]];
currentLocation.name = @"我的位置";
CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(lat.doubleValue, lon.doubleValue);
//目的地的位置
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];
toLocation.name = address;
NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];
NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };
//打開蘋果自身地圖應(yīng)用充蓝,并呈現(xiàn)特定的item
[MKMapItem openMapsWithItems:items launchOptions:options];
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"使用百度地圖導(dǎo)航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (lat.length == 0|| lon.length == 0) {
[QMToastManager showWarning:@"暫無坐標信息"];
return ;
}
NSString *urlString = [[NSString stringWithFormat:@"[baidumap://map/direction?origin={{我的位置}}&destination=%@,%@&coord_type=gcj02](baidumap://map/direction?origin=%7B%7B%E6%88%91%E7%9A%84%E4%BD%8D%E7%BD%AE%7D%7D&destination=%25@,%25@&coord_type=gcj02) &mode=walking&src=%@",lat,lon,appName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"使用高德地圖導(dǎo)航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (lat.length == 0|| lon.length == 0) {
[QMToastManager showWarning:@"暫無坐標信息"];
return ;
}
NSString *urlString = [[NSString stringWithFormat:@"[iosamap://navi?dev=0&sourceApplication=%@&poiname=%@&lat=%@&lon=%@](iosamap://navi?dev=0&sourceApplication=%25@&poiname=%25@&lat=%25@&lon=%25@)",appName ,address,lat,lon] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}];
UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"使用騰訊地圖導(dǎo)航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (lat.length == 0|| lon.length == 0) {
[QMToastManager showWarning:@"暫無坐標信息"];
return ;
}
NSString *urlString = [[NSString stringWithFormat:@"[qqmap://map/routeplan?type=walk&from=我的位置&to=%@&tocoord=%@,%@&referer=%@](qqmap://map/routeplan?type=walk&from=%E6%88%91%E7%9A%84%E4%BD%8D%E7%BD%AE&to=%25@&tocoord=%25@,%25@&referer=%25@)", address, lat, lon, kTengXunMapAppKey] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}];
UIAlertAction *action5 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[controller dismissViewControllerAnimated:YES completion:nil];
}];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"[http://maps.apple.com](http://maps.apple.com)"]]) {
[controller addAction:action1];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
[controller addAction:action2];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
[controller addAction:action3];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
[controller addAction:action4];
}
[controller addAction:action5];
[CurrentAppDelegate.window.rootViewController presentViewController:controller animated:YES completion:nil];
}