I am trying to find direction between two location using iOS framework but I am not able to find proper solution .
You can use different methods for finding the direction between two location.
(1) Using Google Maps
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLatitude, currentLongitude, destinationLatitude, destinationLongitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
(2) Using Apple Maps:
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f", currentLatitude, currentLongitude, destinationLatitude, destinationLongitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
Please let me know if you need any help.
your question is not very clear, but i think you mean the bearing between two locations.
see this question:
Calculating bearing between two CLLocationCoordinate2Ds
If your points are close together just use trigonometry. That will be close enough. If they are farther away then you want a great circle course, use the Haversine formula.
Related
How can I add transport type when showing Directions on map
I have used this code so far, but it is showing Walking distance on map
NSURL *URL = [NSURL URLWithString:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"];
[[UIApplication sharedApplication] openURL:URL];
You can add one extra param directionsmode for different direction mode like below :
NSURL *URL = [NSURL URLWithString:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&directionsmode=transit"];
There are many types of direction mode :
driving
transit
bicycling
walking
Also you can use URLSchema for open app with schema like below Google Map Guide
Google Map URLSchema Guide : https://developers.google.com/maps/documentation/ios-sdk/urlscheme
I am facing an issue while dialing a call as it is automatically assigning international or local prefixes when making calls for toll free local numbers Which starts with one to ISD
NSString *phNo = #"18605003000";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",phNo]];
NSLog(#"in call");
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
}
For above code, when Dail assist is ON, it is prefixing number and converting with +1 (860) 500-3000 which is actually a Indian toll free redirecting to ISD to call ..To avoid this I want to check whether Dail assist is ON or way to disable this programatically.
I have even referred this iOS dial assist auto formats local number to USA number but this way it is Dailing to wrong number
So can any please suggest me for possible way?
I tried the code, and had the dial assist on, but it dialed "18005003000" and did not converted to +1 (800) 500-3000
NSURL *url = [NSURL URLWithString:#"tel://18005003000"];
[[UIApplication sharedApplication] openURL:url];
I'm trying to open the google maps app with a destination address in latitude and longitude. I tried like this:
[NSURL URLWithString:#"comgooglemaps://?daddr=51.140566,4.441389k&directionsmode=driving"]];
But it gives me always that there are no routes.
Can point me out on what I'm doing wrong?
Found the problem. I've had a extra k in my parameter from copy pasting the long and lats.
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:[NSString stringWithFormat:#"comgooglemaps://?daddr=%#,%#&directionsmode=driving", latitude, longitude]]];
This is most likely a very obvious answer, but I am just not seeing it. I want to open the phone application when I click a button.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://???????"]];
That line of code should do it. The problem is, depending on what happens in the app, I want it to dial a different number. I made a string variable, and I want to put it into the space with the ???
Something like:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://(myPhoneNumberString)"]];
Any ideas?
Thanks
Take a look at the NSString documentation.
Something like that will work:
[ NSURL URLWithString: [ NSString stringWithFormat: #"tel://%#", myPhoneNumberStringVar ]
String format is basically the same as in the printf C function, with the additional %# format, used to print object representations.
I'm using google maps to get directions from one place to another. Here is the code
NSString *mapAPIString = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
sourceAddress.coordiate.latitude,
sourceAddress.coordiate.longitude,
destAddress.coordiate.latitude,
destAddress.coordiate.longitude,
];
NSURL *url = [[NSURL alloc] initWithString:mapAPIString];
[[UIApplication sharedApplication] openURL:url];
The code works perfect. But both addresses are marked as 'Unknown address' in iOS Map App. Is it possible to add custom title for each address ?
iOS 6 is still under NDA, but if you have access to the docs have a look at them and you will probably find useful information for this problem.