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

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

    For iOS6 Maps App, you can just use the same URL posted above http://maps.google.com/maps?saddr=%f,%f&daddr=%@

    but instead of the Google maps URL, you use the url with maps:// resulting in the following URL: maps://saddr=%f,%f&daddr=%@.

    Using 'Current Location' doesn't seem to work, so I stayed with the coordinates.

    Antother good thing: It's backwards compatible: On iOS5, it launches the Google Maps app.

    0 讨论(0)
  • 2020-12-02 04:38

    You can do this now in html just from a url on your mobile device only. Here's an example. The cool thing is if you turn this into a qr code you have a way of someone getting directions to you from wherever they are just by scanning it on their phone.

    0 讨论(0)
  • 2020-12-02 04:38

    I answered this on a different thread. (Current Location doesn't work with Apple Maps IOS 6). You need to get the coordinates of the current location first, then use it to create the map url.

    0 讨论(0)
  • 2020-12-02 04:39

    With the current version of Google Maps, simply omit the sadr parameter:

    saddr: … If the value is left blank, then the user’s current location will be used.

    https://developers.google.com/maps/documentation/ios/urlscheme

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-02 04:42

    My suggestion would be using OpenInGoogleMaps-iOS as this is an up to date choice (by November 2015), it supports cocoa pods installation and you are ready to go in a few clicks.

    Install using: pod "OpenInGoogleMaps"

    Require in header file using: #import "OpenInGoogleMapsController.h"

    Sample code below:

    /*In case the user does NOT have google maps, then apple maps shall open*/
    [OpenInGoogleMapsController sharedInstance].fallbackStrategy = kGoogleMapsFallbackAppleMaps;    
    
    /*Set the coordinates*/
    GoogleMapDefinition *definition = [[GoogleMapDefinition alloc] init];   
    CLLocationCoordinate2D metsovoMuseumCoords;     //coordinates struct
    metsovoMuseumCoords.latitude = 39.770598;
    metsovoMuseumCoords.longitude = 21.183215;
    definition.zoomLevel = 20;
    definition.center = metsovoMuseumCoords;        //this will be the center of the map
    
    /*and here we open the map*/
    [[OpenInGoogleMapsController sharedInstance] openMap:definition];       
    
    0 讨论(0)
提交回复
热议问题