Maps.app is not opening programmatically - iphone

NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLocation.latitude, currentLocation.longitude, coordinate.latitude, coordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
I am trying open Maps application on iPhone from my application to show direction between two location. But, it is showing written directions in safari from google rather than opening maps application. Can anybody help me out.

You can launch other apps from your app. However, maps should respond to the http://maps.google.com schema. Typically, http://maps.google.com/ should launch the Maps application but I'm not sure why it is not.
Maps also supports maps:// and mapitem:// URL Schemes.
Update
The iOS Simulator does not have the Maps app, so obviously this isn't going to work in the simulator. Works as expected on a physical device though.

Related

how to change default browser on iphone?

I am new to iOS and I want to know that, How to change the default browser as Google chrome on iPhone Simulator?
Thank you in advance.
As xlc has mentioned the Simulator doesn't allow you to install third party applications. It's designed to let you test your code and how it interacts with iOS.
You cannot change default iOS default browser unless and until your device is jailbroken.
but you can open links in google chrome from your app using :
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"googlechrome://http://www.nameofwebsitehere.com"]];
Note : this will not work on simulator and you should add a check to see if Google chrome is installed on device.

Opening URL in browser using C++ with cocos2d-x in iOS

I'm banging my brain against the wonderful lib xport that is cocos2d-x from the original cocos2d iOS library.
What I want to ask is how to open a web link in the safari browser? I don' know how to link the original objc code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:]];
I have tried using the LUA engine, that is capable of executing shell commands, but I cannot find the safari app path to launch it.
Thanks, people.
You can't get the paths to other applications. However, if you make that openURL: call to open a URL with the http:// domain then Safari will open it. Have you tried that? What result do you get?
UPDATE:
Caveat: I'm not sitting in front of a machine where I can test this.
NSURL * url = [NSURL URLWithString:#"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL: url];
That should be all that is required. UIKit will switch to Safari and browse to the supplied URL.

How to know google maps is installed in iPhone

I am developing an application in which i need to know which are already installed in iPhone device such as google maps. I need to check it. cause I know some country can't support google maps. In this case, what can I do that?
Normally you can't unless you find an API. And even if you find it, there are chances you get rejected from the AppStore.
However, you can try with the URL schemes. For Google Maps, it will invoke the application of it finds an URL starting with http://maps.google.com/.
So, add this function to your code :
- (BOOL)isGoogleMapsInstalled {
return [[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=Paris"]];
}
It's not very "clean" but should works.

Map URL in app goes to Safari, not native map app

I am trying to use a URL to launch the native maps application. My build is for 3.1.3 and later. When I run the following code, safari launches with the URL instead of google maps:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps"]];
Any suggestions?
Thanks!
It sounds to me like you are running on the simulator not hardware. This behavior occurs when the map app is not installed or if you are on the simulator.
If you are running on hardware - have you tried that same style with a specific query or location or with http://maps.google.com as the documentation you pointed to mentions that The path cannot be /maps/*. - I'm not sure if that means explicitly *. or if they mean a wildcard. I'm not really clear why you'd want to launch the map app without a specific query.
Your string needs to be #"maps://maps.google.com/...". That "maps" at the front of it is what triggers it to load the Maps.app application.

Open Photos app programmatically

Is it possible to launch the "Photos" application from an iPhone app? Similar to launching mail?
[[UIApplication sharedApplication] openURL:url];
The Photos app doesn't appear to register any URL schemes that other apps can use. There's a pretty well-established pattern in other system apps (e.g. Safari) of “saving an image” resulting in that image being placed in the user's camera roll; I'd recommend just sticking with that expected behavior, and perhaps using an alert to direct the user to look there for your app's exported image.
This article looks like it might be useful?
Getting images from the iPhone