IOS MapKit Driving Speed ββOver Time
When you are looking for a city, etc. on apple maps, it also shows the time it takes to move it next to the pointer. Is this something built in the mapKit API?
My code so far:
import UIKit
import MapKit
class ShowMapViewController: UIViewController {
var annotation:MKAnnotation!
var localSearchRequest:MKLocalSearchRequest!
var localSearch:MKLocalSearch!
var localSearchResponse:MKLocalSearchResponse!
var error:NSError!
var pointAnnotation:MKPointAnnotation!
var pinAnnotationView:MKPinAnnotationView!
//Map
@IBOutlet weak var mapView: MKMapView!
//Exitbutton
@IBAction func exitMapButtonDidTouch(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
//TODO: Search zip, if not found search city
localSearchRequest = MKLocalSearchRequest()
localSearchRequest.naturalLanguageQuery = "My city"
localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.startWithCompletionHandler { (localSearchResponse, error) -> Void in
//Show city if zip not found
if localSearchResponse == nil{
var alert = UIAlertView(title: nil, message: "Place not found", delegate: self, cancelButtonTitle: "Try again")
alert.show()
return
}
//Show map and pointer
self.pointAnnotation = MKPointAnnotation()
//self.pointAnnotation.title = "My city"
self.pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: localSearchResponse.boundingRegion.center.latitude, longitude: localSearchResponse.boundingRegion.center.longitude)
self.pinAnnotationView = MKPinAnnotationView(annotation: self.pointAnnotation, reuseIdentifier: nil)
self.mapView.centerCoordinate = self.pointAnnotation.coordinate
self.mapView.addAnnotation(self.pinAnnotationView.annotation)
}
}
}
With this, I can add a title above the pointer, but is it possible to show the time and distance?
Thank you in advance
source to share
Yes, that's what's built into Apple! It is called MKRoute
and can give you the travel time between two points.
You can create MKRoute
after preliminary formatting MKDirectionsRequest
.
Here's a link from a project that uses MKDirectionsRequest to apple documentation and a link to EVEN MORE helpful documentation on the subject.
Good luck!
source to share