【问题标题】:iPhone SDK 6 Launching maps with voice navigation directionsiPhone SDK 6 启动带有语音导航方向的地图
【发布时间】:2012-12-03 07:19:42
【问题描述】:

我正在尝试从我的 iPhone SDK 应用程序启动地图应用程序。现在我可以启动带有路线的地图应用程序,但它会转到路线概览,并且不使用 Siri 和语音导航来提供转弯路线。

目前我有一个启动此代码的按钮...

NSString *address = viewedObject.addressFull;
NSString *url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=%f,%f&daddr=%@", here.latitude, here.longitude, [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

【问题讨论】:

    标签: iphone ios6 core-location ios5


    【解决方案1】:

    我建立在上面的 progrmr 答案之上...下面的代码将采用地址的 NSString 输入,然后转发地理编码,然后打开地图应用程序,并通过语音导航到 NSString 输入的方向。 NameString 和 PhoneString 附加到放置在地图应用程序上的地标上。如果没有上面的 progrmr 代码,下面的代码是不可能的,请将他的答案标记为有用。

        [self.geocoder geocodeAddressString:AddressString completionHandler:^(NSArray *placemarks, NSError *error) {
    
            if ([placemarks count] > 0) {
                CLPlacemark *placemark = [placemarks objectAtIndex:0];
                CLLocation *location = placemark.location;
                CLLocationCoordinate2D there = location.coordinate;
    
                MKPlacemark *destPlace = [[MKPlacemark alloc] initWithCoordinate:there addressDictionary:nil];
                MKMapItem *destMapItem = [[MKMapItem alloc] initWithPlacemark:destPlace];
                destMapItem.name = NameString;
                destMapItem.phoneNumber = PhoneString;
    
                NSArray* mapItems = [[NSArray alloc] initWithObjects: destMapItem, nil];
                NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsDirectionsModeKey, nil];
                [MKMapItem openMapsWithItems:mapItems launchOptions:options];
            }
        }];
    

    【讨论】:

    • 这个有语音导航吗?
    • 是的,它确实在支持该功能的设备上提供了语音导航功能。
    【解决方案2】:

    iOS 6 提供了一种启动地图的新方法,在 MKMapItem 中使用 openMapsWithItems:。这是我使用的一个 sn-p,它提供从当前位置到提供的坐标的步行或驾车路线:

    // iOS 6.0+ only
    MKPlacemark* destPlace = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
    MKMapItem* destMapItem = [[[MKMapItem alloc] initWithPlacemark:destPlace] autorelease]; destMapItem.name = stationItem.title;
    
    NSArray* mapItems = [[[NSArray alloc] initWithObjects: destMapItem, nil] autorelease];
    NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
                                     walking ? MKLaunchOptionsDirectionsModeWalking : MKLaunchOptionsDirectionsModeDriving,
                                     MKLaunchOptionsDirectionsModeKey, nil];
    [MKMapItem openMapsWithItems:mapItems launchOptions:options];
    

    按照您的操作方式,如果在 iOS 6 之前的设备上运行,您仍然需要这样做,您需要在 URL 中包含 dirflg 以请求步行或驾车路线:

    // pre iOS 6 code
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=%c",
        currentLocation.coordinate.latitude,
        currentLocation.coordinate.longitude,
        destination.coordinate.latitude,
        destination.coordinate.longitude,
        walking ? 'w' : 'd'];
    

    【讨论】:

    • 感谢您的帮助...只有 iOS 6.0+ 正是我想要的。
    • 我试过了,但看不到语音导航...这是否提供轮流语音导航...?
    • @Surbhit Thanvi 你有没有找到任何关于语音导航的东西?
    • 这两个代码 sn-ps 都提供转弯语音导航,walking 值必须为 NO 才能获得转弯驾驶方向。如果walking 为YES,那么您将获得步行路线。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多