Lee-Loi Lee-Loi - 9 months ago 47
HTML Question

iOS open link with maps

I'm working on an event app and I'm trying to add a "Get direction" button that opens up directions in either Apple maps or google maps. I'm happy to use Apple maps for now because it's easy to embed with "http://maps.apple.com/?q=XYZ()".

Now, I'm not the best iOS developer so basically my app is displaying a HTML website with a UI web view so this may be the problem but when you press the link it actually opens within UI Web view and displays Google maps randomly but accurately however is there a function I can put into my HTML code that forces the link to open in the native Apple or Google maps?

Any help would be much appreciated!

Answer Source

Here you can find info on the Google Maps URL Scheme

UIApplication.sharedApplication().openURL(NSURL(string:
  "comgooglemaps://?q=XYZ")!)

Will enforce Google Maps to be used. You might want to do

UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)

first, to ensure that Google Maps is available. If not, simply call your regular

http://maps.apple.com/?q=XYZ() 

to open apple maps.