Presenting a walkway from position A to B in my app - iphone

So I have an iPhone app which should aid the user to find a convenient walkway from his/her own position to a given destination. As I have learnt, MKMapView does not provide an easy way to infer a preferred walking route from A to B.
I can live with terminating my own app and launch the native map application on the iPhone, but in that case I would like to equip the map application with two coordinates so that the user can find his/her way.
Any suggestions to how I should go about this task?

To launch the native map app use:
NSString *googleMapsURL = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
start.latitude, start.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURL];
where start is the user location and destination is, well, the destination. For walking directions, you can add &dirflg=w (still in beta according to wiki). Here are some more parameters you can use.

Related

Is it possible to send the data from myown app to the iOS MapsApp?

In my app using latitude and longitude values dropped the pins.so,i need to get the direction between those 2 pins in iOSMaps App.Is that possible to show the direction between 2 pins in iOS MapsApp.
yes you can do this. Please have a Look at
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html
You can pass two location via URL Scheme to the apple map app.
Try
- (IBAction)getTest:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino"]];
}
It should open the maps app and show the path between San Francisco and Cupertino.
It should also work with coordinates, but you have to find out yourself ;)
Hope it helps.

Zoom parameter ignored in iPhone maps url link

I want my app to redirect the user to the Maps apps on the iPhone. Search query is fine, it shows the user Current Location and nearby hospitals (hopital in french, it's not a typo), but it doesn't zoom in. I read that the zoom goes from 1 to 19, but even at 18, I still see the entire North America...
NSString *urlString = #"http://maps.google.com/maps?q=hopital&t=m&z=18";
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:urlString]];
I have been reading quite a lot and can't find out why this parameter seems to be ignored.
Any idea? Thanks in advance...
After more searches (for other aspects of the app) and some try/error guesses, I have found an answer which, hopefully, will be helpful to someone else.
This string:
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps?sll=%f,%f&z=14&q=hopital", userCoordinate.latitude, userCoordinate.longitude];
displays the map with a nice zoom, the user's location is centered in the screen and shows relevant searches around. (userCoordinate is a CLLocationCoordinate2D location that contains the user's location.)
Note that with the parameter sll (instead of just ll) displays the same map area but doesn't display the search results. The word (in this case "hopital") is pre-populated in the search box.

How can i use Maps directions app?

I have an app that display locations on the MapView, and i want to get the direction of a specific location from my current location using the Directions APP on the iPhone. how can i do that?
This is a pretty old post from Jeff: http://iphonedevelopment.blogspot.com/2009/02/mapping-directions-from-your-app.html .
From your question, I assume you want to get directions using the Maps app.
To do this you'll need to code something like:
NSString *mapsUrl =
[NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",
self.mapView.userLocation.location.coordinate.latitude,
self.mapView.userLocation.location.coordinate.longitude,
<destination address>];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: [mapsUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];
where saddr is the start address (or lat, lon pair in this case) and daddr is the destination address.
I have done that before. It is basically more trouble than it's worth because you have to implement the directions yourself and every time the Map app gets new features added then the direction system in your app will become outdated. What you really want to do is create a link for the directions to open in the Map app. Owners always make the argument that they don't want the user to have to leave the app, but ultimately you want to provide the best utilities for the user and unfortunately linking to the map app is the way to go here.
You can link to the map app like this:
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:#"http://maps.google.com/whateveryoururlis"];

Open map url in iPhone simulator always redirects

I have written an iPhone app that uses google maps for displaying maps.
I.e.
http://maps.google.com/maps?ll=48.85812229675187,2.294490337371826
with:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
But I always gets redirected to the current location. What am I doing wrong? How can I avoid this?
Try
http://maps.google.com/maps?q=48.85812229675187,2.294490337371826
(notice the q instead of ll)
This lets Maps.app search for the specified location.

Proper method to detect device model (iPhone/iPod Touch)?

Is this the proper way to detect which device a user is running?
NSString *currentModel = [[UIDevice currentDevice] model];
if ([currentModel isEqualToString:#"iPhone"]) {
// The user is running on iPhone so allow Call, Camera, etc.
} else {
// The user is running on a different device (iPod / iPad / iPhone Simulator) disallow Call.
}
It is not a general solution but Apple in many cases provides API calls to check wether specific feature is supported or not. Examples could be:
+isSourceTypeAvailable: and +availableMediaTypesForSourceType: in UIImagePickerController allowing you to check if camera is available for the current device.
+canSendMail in MFMailComposeViewController to check if device is configured to send mail.
-canOpenURL in UIApplication class to check if URL can be opened. For example it can be used to check if it is possible to make a phone call:
if (![[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"tel://"]])
//We cannot make a call - hide call button here
If such API calls are available for your purpose I would use them rather then rely on hardcoded string identifiers.
I'm not sure I'd want to generalize that much (ie, there may eventually be an iPod with a camera, and I don't know that the iPhone will ALWAYS be called "iPhone"), but yes, this is the accepted way.