ios调用百度、高德地图 导航功能
来源:互联网 发布:怎么查网络是否到期 编辑:程序博客网 时间:2024/05/08 12:01
ios调用百度、高德地图 导航功能
要调用第三方app,先要在info.plist中 LSApplicationQueriesSchemes 中增加 app
百度地图:baidumap
高德地图:iosamap
#pragma mark - 导航-(void) gotoStoreShop{ bool hasBaiduMap = NO; bool hasGaodeMap = NO; if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) { hasBaiduMap = YES; } if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) { hasGaodeMap = YES; } if (hasGaodeMap && hasBaiduMap) { UIBAlertView *alert = [[UIBAlertView alloc] initWithTitle:@"提醒" message:@"请选择导航工具!" cancelButtonTitle:@"取消" otherButtonTitles:@"百度地图",@"高德地图",nil]; [alert showWithDismissHandler:^(NSInteger selectedIndex, NSString *selectedTitle, BOOL didCancel) { if (didCancel) { return; } switch (selectedIndex) { case 1://百度地图 [self startBaiduMap]; break; case 2://高德地图 [self startGaodeMap]; break; default: break; } }]; } else if (hasBaiduMap){ [self startBaiduMap]; } else if (hasGaodeMap){ [self startGaodeMap]; } else { ALERT(@"请先安装百度地图或高德地图,才能使用导航功能!"); }}-(void) startGaodeMap{ CLLocationCoordinate2D myLocation = [LocationManager shareManager].location.coordinate; CLLocationCoordinate2D storeLoacation = curStoreLoacal; NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=%f&slon=%f&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&m=0&t=0",@"我的应用", myLocation.latitude, myLocation.longitude,@"我的位置", storeLoacation.latitude, storeLoacation.longitude, storeName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];}-(void) startBaiduMap{ CLLocationCoordinate2D myLocation = [LocationManager shareManager].location.coordinate; CLLocationCoordinate2D storeLoacation = curStoreLoacal; NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:%@&destination=latlng:%f,%f|name:%@&mode=driving", myLocation.latitude, myLocation.longitude, @"我的位置", storeLoacation.latitude, storeLoacation.longitude, storeName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ; [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];}
附加一个自定义UIAlertView选择地图
UIBAlertView.h
//// UIBAlertView.h// TianYiXinForPatient//// Created by huangfeng on 16/3/30.// Copyright © 2016年 Lin. All rights reserved.//#import <Foundation/Foundation.h>@class UIBAlertView;typedef void (^UIBAlertDismissedHandler) (NSInteger selectedIndex, NSString *selectedTitle, BOOL didCancel);typedef BOOL (^UIBAlertShouldEnableFirstOtherButtonHandler)();@interface UIBAlertView : NSObject@property (copy, nonatomic) UIBAlertShouldEnableFirstOtherButtonHandler shouldEnableFirstOtherButtonHandler;// UIAlertView passthroughs@property(nonatomic,assign) UIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(5_0);- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);// UIBAlertView functionality- (id)initWithTitle:(NSString *)aTitle message:(NSString *)aMessage cancelButtonTitle:(NSString *)aCancelTitle otherButtonTitles:(NSString *)otherTitles,...NS_REQUIRES_NIL_TERMINATION;- (void)showWithDismissHandler:(UIBAlertDismissedHandler)handler;@end
UIBAlertView.m
//// UIBAlertView.m// TianYiXinForPatient//// Created by huangfeng on 16/3/30.// Copyright © 2016年 Lin. All rights reserved.//#import "UIBAlertView.h"@interface UIBAlertView() <UIAlertViewDelegate>@property (strong, nonatomic) UIBAlertView *strongAlertReference;@property (copy, nonatomic) UIBAlertDismissedHandler activeDismissHandler;@property (strong, nonatomic) UIAlertView *activeAlert;@end@implementation UIBAlertView#pragma mark - Public (Initialization)- (id)initWithTitle:(NSString *)aTitle message:(NSString *)aMessage cancelButtonTitle:(NSString *)aCancelTitle otherButtonTitles:(NSString *)otherTitles,... { self = [super init]; if (self) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:aTitle message:aMessage delegate:self cancelButtonTitle:aCancelTitle otherButtonTitles:otherTitles, nil]; if (otherTitles != nil) { va_list args; va_start(args, otherTitles); NSString * title = nil; while((title = va_arg(args,NSString*))) { [alert addButtonWithTitle:title]; } va_end(args); } self.activeAlert = alert; } return self;}#pragma mark - Public (Functionality)- (void)showWithDismissHandler:(UIBAlertDismissedHandler)handler { self.activeDismissHandler = handler; self.strongAlertReference = self; [self.activeAlert show];}#pragma mark UIAlertView passthroughs- (UIAlertViewStyle)alertViewStyle{ return self.activeAlert.alertViewStyle;}- (void)setAlertViewStyle:(UIAlertViewStyle)alertViewStyle{ self.activeAlert.alertViewStyle = alertViewStyle;}- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex{ return [self.activeAlert textFieldAtIndex:textFieldIndex];}#pragma mark - UIAlertViewDelegate- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (self.activeDismissHandler) { self.activeDismissHandler(buttonIndex, [alertView buttonTitleAtIndex:buttonIndex], buttonIndex == alertView.cancelButtonIndex); } self.strongAlertReference = nil;}- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{ if (self.shouldEnableFirstOtherButtonHandler) return self.shouldEnableFirstOtherButtonHandler(); return YES;}@end
0 0
- ios调用百度、高德地图 导航功能
- App调用百度高德地图导航
- 关于代码直接调用高德地图和百度地图导航功能的代码
- 调用高德导航,百度导航,腾讯地图
- ios项目中调用百度、高德、本机地图导航(二)
- ios项目中调用百度、高德、本机地图导航
- 调起百度、高德、腾讯地图导航功能
- 地图-导航(百度/高德)
- 调用百度和高德地图导航,好用
- IOS 地图导航(其中包括苹果地图、百度地图、高德地图、谷歌地图)
- Android app调用第三方地图(百度地图,高德地图,谷歌地图)导航
- 安卓通过经纬度,实现intent调用百度,高德,Google地图客户端实现驾车导航功能
- 调用苹果地图、百度地图、高德地图导航(不需要集成sdk)
- Android app调用第三方地图(百度地图,高德地图)导航
- IOS 高德地图导航
- iOS通过CLLocationManager调用地图导航功能
- iOS 跳转到地图后导航(高德地图,百度地图,腾讯地图,苹果手机原生的地图)
- iOS 判断并使用 百度地图 高德地图 导航(使用URI,不集成sdk)
- seq 工具介绍
- Pandas 结构化数据(上)
- 柳峰微信公众平台开发教程企业号修改篇(企业菜单篇)
- Java反射之内部类
- androird 优秀新闻github
- ios调用百度、高德地图 导航功能
- imx6 Uboot 移植小结
- 请求转发和重定向
- 数字签名、数字证书、对称加密算法、非对称加密算法、单向加密(散列算法)
- ORACLE,SQLSERVER等数据库如何获取某张表中相同字段最新一条记录
- Oracle创建表空间、创建用户以及授权、查看权限
- thinking in Java 笔记 6
- IOS开发--使用lookup table为图片添加滤镜
- Windows程序运行原理(总结)