-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *strCoord = nil;
NSString *btnTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([btnTitle isEqualToString:@"百度地图"])
{
if (self.selectedPark.dynamicPark!=nil) {
strCoord = self.selectedPark.dynamicPark.parkingCoordinateBaidu;
}
else
{
strCoord = self.selectedPark.coordinateBaidu;
}
}
else
{
if (self.selectedPark.dynamicPark!=nil) {
strCoord = self.selectedPark.dynamicPark.parkingCoordinateAmap;
}
else
{
strCoord = self.selectedPark.coordinateAmap;
}
}
NSRange range = [strCoord rangeOfString:@","];
if (range.location!=NSNotFound) {
NSString *strLongitude = [strCoord substringToIndex:range.location];
NSString *strLatitude = [strCoord substringFromIndex:range.location+1];
// _naviCoordsGd.longitude = [[strCoord substringToIndex:range.location] floatValue];
// _naviCoordsGd.latitude = [[strCoord substringFromIndex:range.location+1] floatValue];
if (buttonIndex == 0)
{
CLLocationCoordinate2D to;
// to.latitude = _naviCoordsGd.latitude;
// to.longitude = _naviCoordsGd.longitude;
to.longitude = [[strCoord substringToIndex:range.location] floatValue];
to.latitude = [[strCoord substringFromIndex:range.location+1] floatValue];
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:to addressDictionary:nil]];
// toLocation.name = addressStr;
[MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil] launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil] forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]];
}
if ([btnTitle isEqualToString:@"google地图"])
{
// NSString *urlStr = [NSString stringWithFormat:@"comgooglemaps://?saddr=%.8f,%.8f&daddr=%.8f,%.8f&directionsmode=transit",self.userCoordinate.latitude,self.userCoordinate.longitude,self.naviCoordsGd.latitude,self.naviCoordsGd.longitude];
NSString *urlStr = [NSString stringWithFormat:@"comgooglemaps://?saddr=%.8f,%.8f&daddr=%@,%@&directionsmode=transit",self.userCoordinate.latitude,self.userCoordinate.longitude,strLatitude,strLongitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
else if ([btnTitle isEqualToString:@"高德地图"])
{
// NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"iosamap://navi?sourceApplication=broker&backScheme=openbroker2&poiname=%@&poiid=BGVIS&lat=%.8f&lon=%.8f&dev=1&style=2",@"",self.naviCoordsGd.latitude,self.naviCoordsGd.longitude]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"iosamap://navi?sourceApplication=broker&backScheme=openbroker2&poiname=%@&poiid=BGVIS&lat=%@&lon=%@&dev=0&style=2",@"",strLatitude,strLongitude]];
// 这才是真正的吊起地图
[[UIApplication sharedApplication] openURL:url];
}
else if ([btnTitle isEqualToString:@"百度地图"])
{
// double bdNowLat,bdNowLon;
// bd_encrypt(self.userCoordinate.latitude, self.userCoordinate.longitude, &bdNowLat, &bdNowLon);
NSString *stringURL = [NSString stringWithFormat:@"baidumap://map/direction?origin=%.8f,%.8f&destination=%@,%@&&mode=driving",self.userCoordinate.latitude,self.userCoordinate.longitude,strLatitude,strLongitude];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
// else if ([btnTitle isEqualToString:@"显示路线"]){
// [self drawRout];
// }
}