#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)//用来获取手机的系统,判断系统是多少
- (void)ClickNavButton
{
UIAlertController *pAlertController = [UIAlertController alertControllerWithTitle:@"选择导航地图" message:@"若未安装跳到AppStore下载" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *pAlertAppleAction = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
m_pNavImageView.hidden = NO;
[self openAppleMap];
}];
UIAlertAction *pAlertBaiduAction = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
m_pNavImageView.hidden = NO;
[self openBaiduMap];
}];
UIAlertAction *pAlertGaodeAction = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
m_pNavImageView.hidden = NO;
[self openGaodeMap];
}];
UIAlertAction *alertCancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
m_pNavImageView.hidden = NO;
}];
[pAlertController addAction:pAlertAppleAction];
[pAlertController addAction:pAlertBaiduAction];
[pAlertController addAction:pAlertGaodeAction];
[pAlertController addAction:alertCancelAction];
[self presentViewController:pAlertController animated:YES completion:^{
m_pNavImageView.hidden = YES;
}];
}
-(void)openAppleMap{
//获取当前位置
MKMapItem *pMylocation = [MKMapItem mapItemForCurrentLocation];
//当前经维度
float pCurrentLatitude= pMylocation.placemark.location.coordinate.latitude;
float pCurrentLongitude= pMylocation.placemark.location.coordinate.longitude;
m_pcurrentCoords = CLLocationCoordinate2DMake(pCurrentLatitude,pCurrentLongitude);
// ios6以下,调用google map
if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
{
NSString *pstrUrlString = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d", m_pcurrentCoords.latitude,m_pcurrentCoords.longitude,m_pToLocationCoord.latitude,m_pToLocationCoord.longitude];
NSURL *pURL = [NSURL URLWithString:pstrUrlString];
//打开网页google地图
[[UIApplication sharedApplication] openURL:pURL];
}
else
// 直接调用ios自己带的apple map
{
//当前的位置
MKMapItem *pCurrentLocation = [MKMapItem mapItemForCurrentLocation];
//目的地的位置
MKMapItem *pToLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:m_pToLocationCoord addressDictionary:nil]];
pToLocation.name = m_pstrToLocationName; //要显示目的地名字
NSArray *items = [NSArray arrayWithObjects:pCurrentLocation, pToLocation, nil];
NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };
//打开苹果自身地图应用,并呈现特定的item
[MKMapItem openMapsWithItems:items launchOptions:options];
}
}
-(void)openBaiduMap{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]==YES){
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",m_pcurrentCoords.latitude,m_pcurrentCoords.longitude,m_pToLocationCoord.latitude,m_pToLocationCoord.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/bai-du-tu-shou-ji-tu-lu-xian/id452186370?mt=8&v0=WWW-GCCN-ITSTOP100-FREEAPPS&l=&ign-mpt=uo%3D4"]];
}
}
-(void)openGaodeMap{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]==YES){
NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2",@"app name", @"YGche", @"终点", m_pToLocationCoord.latitude, m_pToLocationCoord.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/gao-tu-zhuan-ye-shou-ji-tu/id461703208?mt=8"]];
}
}
IOS选择跳转导航地图,未安装跳到AppStore
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 有时候需要快速实现或者需求需要,要跳转到其他地图应用实现导航,很简单,简单整理一下,请看代码~ De...
- 写在前面: 尽管精确度已然调至最佳, 但还是会有一定程度的定位误差, 作为开发者我已然尽力, 只能希望apple...
- 对跳转高德,百度,苹果,google,腾讯地图导航进行工具类封装 先对info.plist文件进行跳转配置 工具类...