iOS与地图应用程序打开链接 [英] iOS open link with maps apps

查看:98
本文介绍了iOS与地图应用程序打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个活动应用程序,并且正在尝试添加一个获取路线按钮,以在Apple地图或Google地图中打开路线。我很高兴现在使用Apple地图,因为它很容易嵌入 http://maps.apple.com/?q=XYZ()



我的应用程序正在显示带有 UIWebView 的HTML网站,所以这可能是问题所在,但是当您按下链接时在 UIWebView 中打开,并且准确地显示Google地图。是否有一个函数可以放入我的HTML代码中,强制链接在本机Apple或Google Maps中打开? 解决方案

您可以在这里找到有关 Google地图URL计划的信息。

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

将强制使用Google地图。
您可能想要做

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

首先确保Google地图可用。如果没有,只需打电话给您的常规

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

打开苹果地图。


I'm working on an event app and I'm trying to add a "Get directions" 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().

My app is displaying an HTML website with a UIWebView, so this may be the problem, but when you press the link it actually opens within the UIWebView and displays Google Maps randomly but accurately. Is there a function I can put into my HTML code that forces the link to open in the native Apple or Google Maps?

解决方案

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.

这篇关于iOS与地图应用程序打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆