I'm trying to implement a function that open the Apple Map app's driving direction screen by passing actual address.
The address is not just random addresses but business addresses which are mostly registered and searchable on Apple maps. So by passing the address, it should be matched and correctly show direction to that business instead of pointing to an unknown annotation on the map. Such case happens when I pass longitude and latitude directly so I don't want to use geocodeAddressString() to convert the address to geocoordination.
How can I achieve it?
Simply use the Apple Maps API. If you can find a business by tiping its name in Apple Maps, you can find it through the APIs. In your case, the correct parameter is
daddr
, like this:http://maps.apple.com/?daddr=1+Infinite+Loop,+Cupertino,+CA
You can combine multiple parameters, such as your starting location:
http://maps.apple.com/?saddr=1024+Market+St,+San+Francisco,+CA&daddr=1+Infinite+Loop,+Cupertino,+CA
You can find the list of supported parameters here.
Remember to open the URL via
UIApplication.shared().open(url: URL, options: [String: AnyObject], completionHandler: ((Bool) -> Void)?)
- in iOS 10 - orUIApplication.shared.open(url: URL)