josh
josh

Reputation: 1689

Open map within application for iOS6 or previous

I have lat and long of address and I want to open maps for both iPhone Map in iOS6 and Google Map before iOS6 within application. I tried to open map of google for before iOS6 but it not working.

[[UIApplication sharedApplication] canOpenURL:
     [NSURL URLWithString:@"comgooglemaps://?center=46.414382,10.013988&mapmode=streetview"]];

I am doing above line of code mentioned but its not working. Kindly if any one know please help me on that. Thanks in advance.

Upvotes: 0

Views: 167

Answers (1)

Marioea
Marioea

Reputation: 201

There are two different methods: canOpenURL and openURL

With canOpenURL you only check it it is possible to open an external application (in your case the map app -from Apple of from Google-.

Once you have checked it, you have to use [[UIApplication sharedApplication] openURL:NSURL URLWithString] to open it.

So you can try:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps://?center=46.414382,10.013988&mapmode=streetview"]]){
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"comgooglemaps://?center=46.414382,10.013988&mapmode=streetview"]];
}

It is good to use canOpenURL, by this method you check if you are trying to open an app that is not present in the device so you can show an alert of some feedback to the user instead of a not working button without any "visual" action for the user.

Hope it helps.

Upvotes: 1

Related Questions