Showing route to a certain location on a MKMapView iOS? - ios

I'm working on a app that involves a MKMapView, and I need to show a route from the User's current location to a certain location. I've played around with the MKMapView, and I can't find something that would show a route. Any ideas?!?
P.S., If I could also get help on finding out how far apart those two locations are, (User's Location and Certain Location), that would be even more awesome!
Thanks in advance!

For the distance, you may use CLLocation:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
MapKit can give you directions using the MKDirections class. But that is only available for iOS 7 and higher. For older iOS version, you need an external framework/API to calculate the route for you, e.g. Google Directions.
To display a route on the map, you would use Map Overlays (probably MKPolyline and MKPolylineView).

Try it: https://github.com/kadirpekel/MapWithRoutes
Its work for me. But you must do some changes.

There is no way to automatically show a route in an MKMapView. There is support for it in iOS 7, but it's a toolkit of components, not a ready-made feature. It will take a fair amount of development. You will have to query the location manager for route information, then create an overlay layer with polylines based on the route information you get back. I haven't tried this, but I've read about it in the Xcode docs for iOS 7.
The simplest thing to do is to invoke the maps application to display the route for you. That only takes a few lines of code.

Related

StepMilestone | Milestone Listener | Mapbox iOS equivalent

In Mapbox Android SDK, we can able to set/customize the StepMilestone ie we can able to get callbacks before reaching Maneuver of the current step.
Is there any equivalent options available in iOS Mapbox sdk for listening the StepMilestone progress?
Currently on iOS there isn't a direct equivalent, so this is not nearly as straightforward as it is on Android. (disclaimer: I currently work for Mapbox)
The best way to do this on iOS would be to use turf-swift's LineString.distance(from:to:)​ (which is bundled in the Navigation SDK) to find the closest coordinate on the route based on a given POI.
Then you can respond to NotificationName.routeControllerProgressDidChange by comparing that distance to RouteProgress.distanceTraveled. If the user has crossed you specified threshold, create a SpokenInstruction and tell the NavigationViewController’s voiceController to speak(_:) it. You can see a somewhat similar example of this last piece in this example: https://docs.mapbox.com/ios/navigation/examples/custom-voice-controller/
I hope that helps.

iOS 7 find nearest shops around the actual position

I need to find a way to get an list of shops/bars etc. around the actual position of the device.
I know how to get the position. I also know about the Google API Places. But is there an way to solve this without using third party libraries?
You can use the MKLocalSearch API's in MapKit, but you can only do a search for one type of building at a time.
More details can be found in the MapKit Programming Guide - Enabling Search
Otherwise you would have to gather and store the data yourself and query your own system.

How to draw a route between two points(annotations) in Swift?

I would like to ask if somebody can help me with a bit of code...I don't know how to create a route in my map in Swift.I just can draw a polyline between two annotations but it goes out of the roads.How can I connect two annotations on map?but connect them on road...all these is for a bus tour.can somebody help me showing me the code for this in Swift?
In order to trace a road like this, you will need data for the road geometry, but none of Apple's APIs provide this info. You will need to find your own source of geo data that both 1) provides point-by-point info for these routes as well as 2) matches the paths drawn in Apple Maps so that you trace lines up properly.
This is not a trivial problem. It's not likely to be done well using just Apple technology.
One way you could accomplish this is:
Use an alternate, open source of data such as OpenStreetMap.
Use a rendering library that draws such data for its basemap, such as Mapbox.
Combine the OSM data-based base map with individual route OSM-based data such as from the Mapbox Directions API.
The bottom line is that since Apple's maps data is closed, you can't guarantee that anything you draw on top of it is an exact matchup. You need rendering and routing data to be from the same source.

Get the distance from the current location to the final destination by road like in Apple's Maps app

I want to set start location and final destination and get how long it actually is via the roads, like in the map app. I don't know what I'm supposed to search for or what it's called. I think Mapkit is the right framework but I can't seem to find what im looking for.
Sorry dude, but MapKit doesn't have this functionality built into it.
You're best off using the Google Maps API https://developers.google.com/maps/documentation/directions/#DirectionsResponses which gives you distance and driving directions.

How to know a location ( like : (CLLocation *)newLocation)) whether on the road?

I was doing a map ios app using CLLocation and I was wondering whether there is an API for judging whether a point on the map is on the road, but not in an appartment or in anywhere in-side the house?
I have seen there are certain navigation application who can keep the points on the road.
https://github.com/route-me/route-me
Have a look there are so many example in this code you will an google api which provides us the route path latitude and longitutude and we draw a over lay on the map.
Hope this will help you.

Resources