android - html5中URL打开手机上的地图APP
大家讲道理
大家讲道理 2017-04-17 11:51:02
0
2
631

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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
阿神

This is very simple.
For android, you can first read the official documentation
app-intent

The code, I can’t remember it very clearly, it should be like this.

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

For iOS, it is a little more troublesome. You have to open the corresponding APP according to your choice, such as googlemap
google map sdk for ios

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

Or use the official apple map
Map Links

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

So all you have to do is

<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>
小葫芦

Make an intermediate page, such as redirect.html and then add

<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>

As for the specific url and during, you can adjust them yourself. The one I set before seems to be 200 which is enough...

The principle of

application is: if url can be opened, it will jump to the corresponding app

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template