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

后端 未结 16 1701
一整个雨季
一整个雨季 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:32

    You can use a preprocessor #define like:

    #define SYSTEM_VERSION_LESS_THAN(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    

    to understand your iOS version. Then, I can use this code to support iOS 6, too:

    NSString* addr = nil;
    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
       addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
    } else {
       addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
    }
    
    NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [[UIApplication sharedApplication] openURL:url];
    

提交回复
热议问题