showing apple maps with route navigation using siri in iphone programming - iphone

I am showing apple maps with directions from start and end destination.I want it to open and start siri when user opens the map with the route.For some reason its opening the url successfully but not opening the siri to guide the user.
Code used for it is as shown below:
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?daddr=%#&saddr=%f,%f",nativeMapScheme,[description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],mylat, mylon];
NSLog(#"Location - %#",url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Related

How to open a apple maps application with directions from my ios application

My aim is to open a map application from ios application with directions, I am able to open maps application but it is not showing directions, i have written the code as follows
NSString *mystr=[[NSString alloc] initWithFormat:#"http://maps.apple.com/maps?saddr=Current+Location&daddr=Newyork"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
Can any one please help me how figure out how to pass parameters to this url and any other?
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:#selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
if(_mode == 1)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
if(_mode == 2)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
if(_mode == 3)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeTransit}];
}
} else{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
If you mean taking the user to the maps application based on two points, then you can do it like this:
Create an NSURL that looks like this:
NSURL *URL = [NSURL URLWithString:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"];
You plug in your starting address and destination (in lat. and long.) appropriately.
Tell your application to open the URL
[[UIApplication sharedApplication] openURL:URL];
It should take you to the maps application automatically!

iPhone 4 problems dialing from inside app

There is an iOS 5.0+ app, released in App Store, which displays employees profiles with their phone numbers. The users of the app can tap on the phone number and the number will be dialed on their iPhones.
The problem is that some users with iPhone 4 are reporting that it does NOT dial.
This is the code I am using to dial:
NSString *cleanedString = [[self.member.phone componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
[[UIApplication sharedApplication] openURL:urlText];
Any ideas about this?
There shouldn't be any / in the tel: scheme:
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", escapedPhoneNumber]];
In the Apple URL Scheme Reference you can see some example for what is allowed in the tel: scheme.
If you use telpromt instead of tel this will return you to app after your call ends|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt:1234567890"]];

How to start map application on iPhone from objective c

I develop app for IOS 6.
I want to run maps application and pass it start and destination so I can navigate user.
UIApplication *app = [UIApplication sharedApplication];
NSString *coordinates = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f", ...];
[app openURL:[NSURL URLWithString: coordinates]];
I thought that this code will open google maps in browser on simulator, and maps app on device, but on the device it runs browser google map.
Am i doing something wrong?
If you're not aware, Apple no longer uses Google maps so you have to use their new URL scheme for the Apple maps.
(Note: if you're supporting iOS 5, then you should use both. The google maps scheme and apple maps)
Here is an example query http://maps.apple.com/maps?daddr=San+Francisco,+CA&saddr=cupertino
Here is the documentation for it: Apple Maps URL Schemes
Another option, if you have an MKPlacemark object:
// placemark is your MKPlacemark object
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placemark];
if([destination respondsToSelector:#selector(openInMapsWithLaunchOptions:)])
{
// Using iOS6 native maps app
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else
{
// Using iOS5 which has the Google Maps application
NSString *currentLocation = #"Current%20Location";
NSString *routeString = [NSString stringWithFormat:#"%#saddr=%#&daddr=%#", kMapsBaseUrl, currentLocation, address.mapAddress];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:routeString]];
}
This is what I use on iOS 8.
First I try to open the url #"comgooglemaps://", if it works this means that they installed the google maps app, so then I can open the app.
If it doesn't work then the app isn't there, just open google maps in Safari.
In both cases it passes the query q=London.
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"comgooglemaps://"]]){ //open google maps app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"comgooglemaps://?q=London"]];
}
else{ //open browser
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]];
}
-(void)openAddressOnNativeMapApp{
NSString *addressOnMap = #"cupertino"; //place name
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/?q=%#",addressOnMap];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
For More Info visit Apple Doc for open native map App

Open Apple Maps and Start Route from Current Location to Home Immediately in iOS 6.0

I'm wanting to create a link in my application that essentially will be labelled "Take Me Home". When pressed, I want it to open Apple Maps, route from current location to home, and start turn by turn navigation.
I have found this scheme, but it does not do everything I was hoping for:
http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
Here is a working code for opening Maps with routes (including the option to show Google maps for iOS5)
-(IBAction)showMapApp:(id)sender
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:#selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
if(_mode == 1)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
if(_mode == 2)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
if(_mode == 3)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
} else{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
}
Use this For me its working fine::
NSString* url = [NSString stringWithFormat: #"http://maps.apple.com/maps?saddr=44.521358,11.374080&daddr=44.518640,11.362665"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

How to make a call from my application, without quitting my application in iPhone?

I Know how to make a call directly from my application programmatically in iPhone, but before invoking the call , my application is terminating, which is not expected to, my application has to resume back, once the call is quit. How to do this for iPhone programmatically?
Thank You.
See this thread, you can take the code snippet from there as is and use it
making a phone call w/o quitting an appication
Keep in mind that it's possible only from iOS 3.1. If you targeting iOS 3.0 there is no way not to quit the application.
NSString *callString = [NSString stringWithFormat:#"tel:%#", #"412-33-44-55"];
NSURL *url= [NSURL URLWithString:callString];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion compare: #"3.1" options: NSNumericSearch] >= NSOrderedSame ) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[callButton frame]];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:callButton];
[webview release];
}
else {
// On 3.0 and below, dial as usual
NSString * s = [NSString stringWithFormat:#"tel://%#",#"412-33-44-55"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:s]];
}