Search code examples
iosxcodegoogle-maps-sdk-ios

How to open Google Maps click on embed maps in Xcode


I'm trying to open Google Maps app when I click on embed google maps sdk in Xcode. Please help me in order to find the solution?


Solution

  • Add one key in .plist file "LSApplicationQueriesSchemes" and mention one item "comgooglemaps" in that.

    Then try this code.

    if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]]) {
        NSURL *directionsURL = [NSURL URLWithString:@"comgooglemaps://"];
        [[UIApplication sharedApplication] openURL:directionsURL];
    }
    else{
        [[UIApplication sharedApplication] openURL:[NSURL
                                                    URLWithString:@"https://itunes.apple.com/us/app/google-maps/id585027354?mt=8"]];
    }