How to invoke iPhone Maps for Directions with Current Location as Start Address

后端 未结 16 1685
一整个雨季
一整个雨季 2020-12-02 03:53

I know it\'s possible to start the iPhone maps application by calling openURL on a google maps URL with parameters saddr and daddr wit

16条回答
  •  执念已碎
    2020-12-02 04:41

    For iOS6 the apple docs recommend using the equivalent maps.apple.com URL Scheme

    so use

    http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
    

    instead of

    http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f
    

    to be backwards compatible the code would be

        NSString* versionNum = [[UIDevice currentDevice] systemVersion];
        NSString *nativeMapScheme = @"maps.apple.com";
        if ([versionNum compare:@"6.0" options:NSNumericSearch] == NSOrderedAscending)
            nativeMapScheme = @"maps.google.com";
        }
        NSString* url = [NSString stringWithFormat: @"http://%@/maps?saddr=%f,%f&daddr=%f,%f", nativeMapScheme
                 startCoordinate.latitude, startCoordinate.longitude,
                 endCoordinate.latitude, endCoordinate.longitude];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    

    there is a whole load of other supported parameters for the Apple Maps URL scheme : Apple URL Scheme Reference

    you can use these iOS version detection macros if you have conditional code in other parts of your code. iOS version macros

提交回复
热议问题