I am trying to integrate Apple Maps in my iPhone app to show route between two locations. But it wont show any route & will simple print lots of messages in console.
I am located in Mumbai, India. When I tried to use official Maps app on iPhone to search route it gave me warning that, 'No routes found'!
When in simulator I use two predefined location in U.S. it plotted the route, along with alternative routes correctly. So I came to conclusion that, Apple Map service is very limited outside U.S. (especially in India).
I want to use native services as much possible, but now that seems difficult. Do anyone have idea about this issue & it this is the case then what are the other options?
Following are code sample from both cases:
India (No result):
let request: MKDirectionsRequest = MKDirectionsRequest()
request.source = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 19.02, longitude: 72.85), addressDictionary: nil))
request.destination = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 19.12, longitude: 73.85), addressDictionary: nil))
request.transportType = MKDirectionsTransportType.automobile;
request.requestsAlternateRoutes = true
let directions = MKDirections(request: request)
directions.calculate { [unowned self] response, error in
guard let unwrappedResponse = response else { return }
for route in unwrappedResponse.routes {
self.mapView.add(route.polyline)
self.mapView.setVisibleMapRect(route.polyline.boundingMapRect, animated: true)
}
}
U.S. (Gave proper routes)
let request: MKDirectionsRequest = MKDirectionsRequest()
request.source = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 40.71, longitude: -74.00), addressDictionary: nil))
request.destination = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 37.78, longitude: -122.41), addressDictionary: nil))
request.transportType = MKDirectionsTransportType.automobile;
request.requestsAlternateRoutes = true
let directions = MKDirections(request: request)
directions.calculate { [unowned self] response, error in
guard let unwrappedResponse = response else { return }
for route in unwrappedResponse.routes {
self.mapView.add(route.polyline)
self.mapView.setVisibleMapRect(route.polyline.boundingMapRect, animated: true)
}
}
While researching I found this link: http://www.apple.com/in/ios/feature-availability/
In Maps: Directions section India is not listed, so I don't think I'll be able to use this feature in my app :(
I am familiar with Google Maps, but are there any other option to overcome this problem with minimum shift from native services?