Pravin S.
Pravin S.

Reputation: 485

How to draw route (without polylines) and without google api?

I want to draw route on Map without using google API.

I am tracking the user with co-ordinates of user. So i draw polylines to show user route,but now my client wants to remove those polylines and want to show routes like google have. Is it possible in which i can pass all co-ordinates route map drawn on those co-ordinates?

Upvotes: 0

Views: 583

Answers (1)

yuhua
yuhua

Reputation: 1249

Actually you can use MKDirections built-in MapKit Framework. here's the further information: https://developer.apple.com/library/mac/documentation/MapKit/Reference/MKDirections_class/.

Show you some snippet which is calculating the route of two locations:

func caculateDirections(fromCoordinate: CLLocationCoordinate2D, toCoordinate: CLLocationCoordinate2D) {
        let from = MKMapItem(placemark: MKPlacemark(coordinate: fromCoordinate, addressDictionary: nil))
        let to = MKMapItem(placemark: MKPlacemark(coordinate: toCoordinate, addressDictionary: nil))

        let request = MKDirectionsRequest()
        request.source = from
        request.destination = to
        request.transportType = .Automobile

        let directions = MKDirections(request: request)
        directions.calculateDirectionsWithCompletionHandler { (response, error) -> Void in
            if let response = response {
                // Here you can get the routes and draw it on the map
                let routes = response.routes
            } else {
                print("Error:\(error?.description)")
            }
        }
    }

You can learn more from this tutorial: http://www.devfright.com/mkdirections-tutorial/

Upvotes: 1

Related Questions