Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Apple Maps driving direction by passing address

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?

like image 219
androisojavaswift Avatar asked Dec 19 '22 11:12

androisojavaswift


1 Answers

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 - or UIApplication.shared.open(url: URL)

like image 199
Nicola Giancecchi Avatar answered Mar 04 '23 23:03

Nicola Giancecchi