//绘制 这里是ArcGis的代理方法
- (BOOL) callout:(AGSCallout *)callout willShowForFeature:(id<AGSFeature>)feature layer:(AGSLayer<AGSHitTestable> *)layer mapPoint:(AGSPoint *)mapPoint {
//直接跳转应用不使用导航功能使用下方url
NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
if ([[UIApplication sharedApplication] canOpenURL:baidu_App]){
self.mapView.callout.title = @"百度地图";
}else if ([[UIApplication sharedApplication] canOpenURL:gaode_App]){
self.mapView.callout.title = @"高德地图";
}else{
self.mapView.callout.title = @"苹果地图";
}
self.mapView.callout.detail =@"点击箭头跳转";
self.mapView.callout.detailColor = [UIColor grayColor];
self.mapView.callout.accessoryButtonHidden = NO;
self.mapView.callout.accessoryButtonType = UIButtonTypeCustom;
self.mapView.callout.accessoryButtonImage = [UIImage imageNamed:@" marker"];
return YES;
}
- (void)didClickAccessoryButtonForCallout:(AGSCallout *)callout{
NSLog(@"点击跳转");
NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
if ([[UIApplication sharedApplication] canOpenURL:baidu_App]){
//跳转百度地图
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",_startPoint.y, _startPoint.x,_targetPoint.y,_targetPoint.x] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}else if ([[UIApplication sharedApplication] canOpenURL:gaode_App]){
[self testAppleMap];
}else{
[self testAppleMap];
}
}
//跳转苹果地图
-(void)testAppleMap{
NSLog(@"%f____%f------%f-----%f",_startPoint.x,_startPoint.y,_targetPoint.x,_targetPoint.y);
CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(_startPoint.y,_startPoint.x);
CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(_targetPoint.y,_targetPoint.x);
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];
toLocation.name = @"目的地";
NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];
NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES }; //打开苹果自身地图应用,并呈现特定的item
[MKMapItem openMapsWithItems:items launchOptions:options];
}
- (void)testBaidu:(NSString *)title{
NSString *url2 = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:39.915,116.404|name:我的位置&destination=latlng:39.915,120.202|name:终点&mode=driving"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url2]];
// if ([@"使用高德地图导航" isEqualToString:title])
// {
// NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2",@"app name", yourscheme, @"终点", _shopLat, _shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//
// [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];
// }
}
//高德地图未实现
- (BOOL) callout:(AGSCallout *)callout willShowForFeature:(id<AGSFeature>)feature layer:(AGSLayer<AGSHitTestable> *)layer mapPoint:(AGSPoint *)mapPoint {
//直接跳转应用不使用导航功能使用下方url
NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
if ([[UIApplication sharedApplication] canOpenURL:baidu_App]){
self.mapView.callout.title = @"百度地图";
}else if ([[UIApplication sharedApplication] canOpenURL:gaode_App]){
self.mapView.callout.title = @"高德地图";
}else{
self.mapView.callout.title = @"苹果地图";
}
self.mapView.callout.detail =@"点击箭头跳转";
self.mapView.callout.detailColor = [UIColor grayColor];
self.mapView.callout.accessoryButtonHidden = NO;
self.mapView.callout.accessoryButtonType = UIButtonTypeCustom;
self.mapView.callout.accessoryButtonImage = [UIImage imageNamed:@" marker"];
return YES;
}
- (void)didClickAccessoryButtonForCallout:(AGSCallout *)callout{
NSLog(@"点击跳转");
NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
if ([[UIApplication sharedApplication] canOpenURL:baidu_App]){
//跳转百度地图
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",_startPoint.y, _startPoint.x,_targetPoint.y,_targetPoint.x] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}else if ([[UIApplication sharedApplication] canOpenURL:gaode_App]){
[self testAppleMap];
}else{
[self testAppleMap];
}
}
//跳转苹果地图
-(void)testAppleMap{
NSLog(@"%f____%f------%f-----%f",_startPoint.x,_startPoint.y,_targetPoint.x,_targetPoint.y);
CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(_startPoint.y,_startPoint.x);
CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(_targetPoint.y,_targetPoint.x);
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];
toLocation.name = @"目的地";
NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];
NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES }; //打开苹果自身地图应用,并呈现特定的item
[MKMapItem openMapsWithItems:items launchOptions:options];
}
- (void)testBaidu:(NSString *)title{
NSString *url2 = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:39.915,116.404|name:我的位置&destination=latlng:39.915,120.202|name:终点&mode=driving"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url2]];
// if ([@"使用高德地图导航" isEqualToString:title])
// {
// NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2",@"app name", yourscheme, @"终点", _shopLat, _shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//
// [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];
// }
}
//高德地图未实现