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.
I want to figure out how Google Map's API to give us directions.
Create a sample tool where I can use my location as a starting point and choose another location and I can view directions (both driving and walking) in text and on map within my existing application.
I haven't used google map api so I am completely naive about this
can anyone help me with this?
try this,
NSString *urlstring=[NSString stringWithFormat:#"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
What the code do is, it will show the route between your source and destination location on google map.
If you dont have the longitude then you can do it like:-
NSString *source=#"NorthCarolina";
NSString *destination=#"SouthCarolina";
NSString *urlstring=[NSString stringWithFormat:#"http://maps.google.com/?saddr=%#&daddr=%#",source,destination];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
I hope this will help you.Happy coding:)
I have reviewed the Apple Documentation (http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html) on sending a user to the Google Maps App and I have a question, "How do I have it automatically bring up directions from the user's current location to a predetermined lat/long location?
The Apple Docs say to use "saddr=" and "daddr=" for the source and destination respectively, but it doesn't say how to acquire the user's current location. Is there some sort of keyword such as "saddr=Current" or "saddr=Here" that will get the user's location?
Obviously, this doesn't work:
[app openURL:[NSURL URLWithString:#"http://maps.google.com/maps?saddr=Here&daddr=Chicago"]];
..if I was trying to send the user to Chicago. Any thoughts?
SOURCE:
How to invoke iPhone Maps for Directions with Current Location as Start Address
You need to use Core Location to get the current location, but with that lat/long pair, you can get Maps to route you from there, to a street address. Like so:
CLLocationCoordinate2D currentLocation = [self getCurrentLocation];
NSString* address = #"123 Main St., New York, NY, 10001";
NSString* url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",
currentLocation.latitude, currentLocation.longitude,
[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
I don't think you can do this directly. But you can put coordinates into the parameters by using the format saddr=lat,long (e.g. addr=53.453209,-0.32930). So if you work out the user's current location in your app before you despatch to Google Maps, you get an approximation of the functionality.
You can just use Current+Location in the saddr part of the url. That works on iOS, but I can't find what works for Android.
Simply calling the Google Maps URL with just the daddr parameter set, makes Google Maps insert the user's current location automatically in the From field.
http://maps.google.de/maps?daddr=SOMEADDRESS
I believe that saddr=Current%20Location&daddr=... is what you want.
You can always use the reverse geocoder in iOS to get the current locations address (given that the user lets you acquire their location) and use it in the URL, here MKReverseGeocoder is a reference to the class used for reverse geocoding.
-Daniel
NSString* directionsURL = [NSString stringWithFormat:#"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",self.mapView.userLocation.coordinate.latitude, self.mapView.userLocation.coordinate.longitude, mapPoint.coordinate.latitude, mapPoint.coordinate.longitude];
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL] options:#{} completionHandler:^(BOOL success) {}];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL]];
}
You can use CurrentLocation Coordinate in the origin part and destinationLocation Coordinate in the destination part in the url. That works on iOS...
https://maps.googleapis.com/maps/api/directions/json?origin=(originCoordinate)&destination=(destinationCoordinate)&mode=driving&key=YOUR-KEY
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.
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.