如何在滴滴目的地地图上选点同时选多个地物

提供多个地图选择
提供多个地图选择
发布时间: 3:43:58
编辑:www.fx114.net
本篇文章主要介绍了"提供多个地图选择",主要涉及到提供多个地图选择方面的内容,对于提供多个地图选择感兴趣的同学可以参考一下。
#import &MapKit/MapKit.h&
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)//用来获取手机的系统,判断系统是多少
UIActionSheetDelegate 代理
@property(strong ,nonatomic)NSMutableArray *availableM
& 定义可变数组
定义好 地点和终点 (导航的必要条件)
& & & & CLLocationCoordinate2D startC
& & CLLocationCoordinate2D endC
&startCoor =CLLocationCoordinate2DMake([YFMapMessage
sharedInstance].coordinate.latitude,[YFMapMessage
sharedInstance].coordinate.longitude);
& & if (_dataArray.count==1) {
& & & & YFMapItemModel *model =
_dataArray[0];
& & & & endCoor =
CLLocationCoordinate2DMake(model.merchantsCoord.latitude, model.merchantsCoord.longitude);
& & self.availableMaps=[[NSMutableArray
alloc] init];
//& & if (SYSTEM_VERSION_LESS_THAN(@&6.0&)) { // ios6以下,调用google map
// & & & &
//& & & & NSString *urlString = [[NSString alloc] initWithFormat:@&/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d&,startCoor.latitude,startCoor.longitude,endCoor.latitude,endCoor.longitude];
//& & & & //& & & & @&/?saddr=%f,%f&daddr=%f,%f&,startCoor.latitude,startCoor.longitude,endCoor.latitude,endCoor.longitude
//& & & & urlString =& [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//& & & & NSURL *aURL = [NSURL URLWithString:urlString];
//& & & & [[UIApplication sharedApplication] openURL:aURL];
//& & } else { // 直接调用ios自己带的apple map
// & & & &
//& & & & MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
//& & & & MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:endCoor addressDictionary:nil]];
//& & & & toLocation.name = @&to name&;
// & & & &
//& & & & [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
// & & & & & & & & & & & launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
// & & & &
& & UIButton *btn=[UIButton
buttonWithType:UIButtonTypeCustom];
& & [btn setTitle:@&开始导航&
forState:UIControlStateNormal];
& & btn.titleLabel.font=FONT(19);
& & [btn setTitleColor:[UIColor
redColor] forState:UIControlStateNormal];
& & [btn addTarget:self
action:@selector(pressMore)
forControlEvents:UIControlEventTouchUpInside];
& & [btn setFrame:CGRectMake(kScreenWidth-100,
kScreenHeight-120,
& & [self.view
addSubview:btn];
-(void)pressMore
& & //注释掉通过百度SDK&
& & if (![self checkServicesInited])
& & & & return;
& & _naviType = BN_NaviTypeR
& & [self startNavi];
availableMapsApps];
& & UIActionSheet *action = [[UIActionSheet
alloc] init];
& & [action setTitle:@&请选择地图& ];
& & [action addButtonWithTitle:@&使用高德地图导航&];
& & for (NSDictionary *dic
in self.availableMaps) {
& & & & [action addButtonWithTitle:[NSString
stringWithFormat:@&使用%@导航&, dic[@&name&]]];
& & [action addButtonWithTitle:@&取消&];
& & action.cancelButtonIndex =
self.availableMaps.count +
& & action.delegate =
& & [action showInView:self.view];
- (void)availableMapsApps {
& & [self.availableMaps
removeAllObjects];
//& & CLLocationCoordinate2D startCoor = self.mapView.userLocation.location.
//& & CLLocationCoordinate2D endCoor = CLLocationCoordinate2DMake(startCoor.latitude+0.01, startCoor.longitude+0.01);
& & NSString *toName =
@&to name&;
& & if ([[UIApplication
sharedApplication] canOpenURL:[NSURL
URLWithString:@&baidumap://map/&]]){
& & & & NSString *urlString = [NSString
stringWithFormat:@&baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:%@&mode=transit&,
&& & & & & & & & & & & & & & & startCoor.latitude,
startCoor.longitude,
endCoor.latitude,
endCoor.longitude, toName];
& & & & NSDictionary *dic =
@{@&name&:
@&百度地图&,
& & & & & & & & & & & & & & & @&url&: urlString};
& & & & [self.availableMaps
addObject:dic];
& & if ([[UIApplication
sharedApplication] canOpenURL:[NSURL
URLWithString:@&iosamap://&]]) {
& & & & NSString *urlString = [NSString
stringWithFormat:@&iosamap://navi?sourceApplication=%@&backScheme=applicationScheme&poiname=fangheng&poiid=BGVIS&lat=%f&lon=%f&dev=0&style=3&,
&& & & & & & & & & & & & & & & @&云华时代&,
endCoor.latitude,
endCoor.longitude];
& & & & NSDictionary *dic =
@{@&name&:
@&高德地图&,
& & & & & & & & & & & & & & & @&url&: urlString};
& & & & [self.availableMaps
addObject:dic];
& & if ([[UIApplication
sharedApplication] canOpenURL:[NSURL
URLWithString:@&comgooglemaps://&]]) {
& & & & NSString *urlString = [NSString
stringWithFormat:@&comgooglemaps://?saddr=&daddr=%f,%f?er=%f,%f&directionsmode=transit&,
endCoor.latitude,
endCoor.longitude,
startCoor.latitude,
startCoor.longitude];
& & & & NSDictionary *dic =
@{@&name&:
@&Google Maps&,
& & & & & & & & & & & & & & & @&url&: urlString};
& & & & [self.availableMaps
addObject:dic];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
& & if (buttonIndex ==
//& & & & CLLocationCoordinate2D startCoor =
//& & & & CLLocationCoordinate2D endCoor =
& & & & if (SYSTEM_VERSION_LESS_THAN(@&6.0&)) {
// ios6以下,调用google map
&& & & & & &
& & & & & & NSString *urlString = [[NSString
alloc] initWithFormat:@&/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d&,startCoor.latitude,startCoor.longitude,endCoor.latitude,endCoor.longitude];
& & & & & & //& & & & @&/?saddr=%f,%f&daddr=%f,%f&,startCoor.latitude,startCoor.longitude,endCoor.latitude,endCoor.longitude
& & & & & & urlString =& [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
& & & & & & NSURL *aURL = [NSURL
URLWithString:urlString];
& & & & & & [[UIApplication
sharedApplication] openURL:aURL];
& & & & } else{//
直接调用ios自己带的apple map
&& & & & & &
& & & & & & MKMapItem *currentLocation = [MKMapItem
mapItemForCurrentLocation];
& & & & & & MKPlacemark *placemark = [[MKPlacemark
alloc] initWithCoordinate:endCoor
addressDictionary:nil];
& & & & & & MKMapItem *toLocation = [[MKMapItem
alloc] initWithPlacemark:placemark];
& & & & & & toLocation.name =
@&to name&;
&& & & & & &
& & & & & & [MKMapItem
openMapsWithItems:@[currentLocation, toLocation]
&& & & & & & & & & & & & & launchOptions:@{MKLaunchOptionsDirectionsModeKey:
MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber
numberWithBool:YES]}];
&& & & & & &
if (buttonIndex & self.availableMaps.count+1)
& & & & NSDictionary *mapDic =
self.availableMaps[buttonIndex-1];
& & & & NSString *urlString = mapDic[@&url&];
& & & & urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
& & & & NSURL *url = [NSURL
URLWithString:urlString];
& & & & DLog(@&\n%@\n%@\n%@&, mapDic[@&name&], mapDic[@&url&],
urlString);
& & & & [[UIApplication
sharedApplication] openURL:url];
刚开始不能跳转 ,因为要在plist里面设置 跳转到app的 标示
在更新iOS9后原来的方法不起做用了。解决办法:
在info.plist添加白名单
&key&LSApplicationQueriesSchemes&/key&
& & &&string&baidumap&/string&
& & &&string&iosamap&/string&
&string&comgooglemaps&string&
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

参考资料

 

随机推荐