首页 > html5中URL打开手机上的地图APP

html5中URL打开手机上的地图APP

html5中URL打开手机上的地图APP,能做到吗?比如我手机上装了几个地图APP,提示我自由选择用那个?请高手


做一个中间页面,比如 redirect.html 然后加入

<script type="text/javascript">
    window.location.href = "appleMap://";
    setTimeout( function(e){ window.location.href = "gmap://"; },200);
    setTimeout( function(e){ window.location.href = "bdmap://";....},400);
   setTimeout( function(e){ window.location.href = "gmap://";},600};
</script>

至于具体的 urlduring 自己调吧,我以前设置的好像 200 就够用了...

应用的原理就是:如果 url 能打开,则会跳转到相应 app


这个很简单。
android的话,你可以先看看官方的文档
app-intent

代码,我记不得非常清晰了,应该是这样的。

Uri uri = Uri.parse("geo:0,0"); // 0, 0代表经纬度
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

iOS的话就稍微麻烦一些,你要自己根据选择去打开对应的APP,比如googlemap
google map sdk for ios

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]]

或者使用官方的apple map
Map Links

NSURL *url = [NSURL URLWithString:@"http://maps.apple.com/?q=cupertino"]

所以你要做的就是

<html>
    <body>
        <!-- android -->
        <a href="geo:0,0">my location</a>
        <!-- ios -->
        <a href="http://maps.apple.com/?q=cupertino">my location</a>
    </body>
</html>
【热门文章】
【热门文章】