Zoom parameter ignored in iPhone maps url link - iphone

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.

Related

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"];

how to use Google Map's API in Iphone?

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:)

iOS Google Maps Question

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

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.

Presenting a walkway from position A to B in my app

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.