Question

I've implemented a simple app with a Mapkit that shows one pin for a certain address. If I click on this pin, I can see the details of the location and the disclosure indication. At this point, I would like to enable the user to obtain directions from his location to there.

The only idea I had, it was to push a web view that opens an url in Google Maps with the desired coordinates. Are there many effective and usable ways to do this? Any other ideas?

Thanks in advance, yassa

Was it helpful?

Solution

You have to decide if you want to embed a UIWebView or let the user go to the maps app. You sort of lose "user connection" if you let the user out of your app but the user experience in the maps app is far better than the web experience. For that reason, I went with the maps app.

See http://wiki.akosma.com/IPhone_URL_Schemes#Maps for how to launch the maps app via UIApplication openURL.

Note that if the maps app isn't installed (just the simulator?) this will open the web page, but in Safari rather than in an embedded UIWebView.

OTHER TIPS

Actually, in iOS7 you can give directions within your app using MapKit. Here is my source. And I quote:

MKDirectionRequest and MKDirectionResponse Many mobile users rely on directions from their device and in iOS 7 developers can now provide them within the context of your app instead of switching to the Maps application. You start your request with a source and destination. Other options include alternate routes, transport type and time of departure/arrival.

MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init]; 
> request.source = source;  request.destination = destination; 
> request.requestsAlternateRoutes = YES;    MKDirections *directions =
> [[MKDirections alloc] initWithRequest:request];  [directions
> calculateDirectionsWithCompletionHandler: ^(MKDirectionsResponse
> *response, NSError *error) {      if (error) {        NSLog(@"Error is %@",error);    } else {        [self showDirections:response];     }  }];

The

MKDirectionsResponse provides a plethora of information that includes an array of MKRoutes, each of which contain an array of MKRouteStep so that you can provide each step of directions to get your user to their location. By putting the MKRoute and MKRouteSteps in an array, it makes it easy to display the information in a table or display the information on a map as in:

for (MKRoute *route in _response.routes) {      [_mapView
> addOverlay:route.polyline level: MKOverlayLevelAboveRoads];  }

Results may be updated frequently as a user moves with their device so don’t cache the results for long.

With a similar feature in the Google Maps API, Google imposes a limit to the number of requests your app can have in a day. Apple has chosen to go a different direction and rate limit each device instead, which means there are no per-app or per-developer usage limits. A device may be throttled if it reaches high usage, which is intended to restrain apps that would be doing something like recursively making requests.

Sorry if this answer is formatted strangely, I find all that quotes and code formatting difficult. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top