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

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

    The real solution can be found here. Z5 Concepts iOS Development Code Snippet

    It just requires a little bit of encoding.

    - (IBAction)directions1_click:(id)sender
    {
        NSString* address = @"118 Your Address., City, State, ZIPCODE";
        NSString* currentLocation = @"Current Location";
        NSString* url = [NSStringstringWithFormat: @"http://maps.google.com/maps?saddr=%@&daddr=%@",[currentLocation stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        UIApplication *app = [UIApplicationsharedApplication];
        [app openURL: [NSURL URLWithString: url]];
    }
    

提交回复
热议问题