调用地图的导航功能

-(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];
//        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值