-1

I am adding a few location to my app. I have it where it defaults opening these locations in Apple maps. But I want to make it where if the user has Google maps downloaded they will have the choice to open it in Google maps. So how do I get Xcode in Objective-c to see if the user has Google Maps on their phone? the way I use to do it doesn't seem to be working anymore.

This is What I have been using

-(IBAction)parkerMap {
{

    BOOL isAppInstalled=[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"google.maps://"]];
    if(isAppInstalled)
    {
        UIAlertController* maps = [UIAlertController alertControllerWithTitle:@"" message:@"Would you like to open in Apple or Google Maps?"
                                                               preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* appleAction = [UIAlertAction actionWithTitle:@"Apple" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.apple.com/?address=68,D.L.WeatherlyLn.,38388"] options:@{} completionHandler:nil];
                                                         }];
        UIAlertAction* googleAction = [UIAlertAction actionWithTitle:@"Google" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com/maps/place/68+D.L.+Weatherly+Ln,+Wildersville,+TN+38388/          @35.7776813,-88.3943264,17z/data=!3m1!4b1!4m5!3m4!1s0x887c717763333487:0x8ac40c35453bbb84!8m2!3d35.777677!4d-88.3921377"] options:@{} completionHandler:nil];
                                                          }];

        [maps addAction:appleAction];
        [maps addAction:googleAction];
        [self presentViewController:maps animated:YES completion:nil];
         }
    else
    {

       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.apple.com/?address=68,D.L.WeatherlyLn.,38388"] options:@{} completionHandler:nil];
    }

}
}

enter image description here

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
Josh Kern
  • 3
  • 2

1 Answers1

0

See here

if ([[UIApplication sharedApplication] canOpenURL:
     [NSURL URLWithString:@"comgooglemaps://"]]) {
  [[UIApplication sharedApplication] openURL:
   [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
} else {
  NSLog(@"Can't use comgooglemaps://");
}

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

Sargis
  • 1,196
  • 1
  • 18
  • 31
  • Still not recognizing that I have the google maps app. But when I put @"comgooglemaps://" as the action it opens Google maps. Oh well, thanks anyways. – Josh Kern Jul 18 '18 at 07:11
  • I have made apps before Where I have used @"fb://" and @"twitter://" to check for facebook and Twitter. And even those aren't working anymore. So I don't know if it's something on my end or theirs. – Josh Kern Jul 18 '18 at 07:28
  • You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist. LSApplicationQueriesSchemes comgooglemaps – Sargis Jul 18 '18 at 07:32