html5中URL打开手机上的地图APP,能做到吗?比如我手机上装了几个地图APP,提示我自由选择用那个?请高手
光阴似箭催人老,日月如移越少年。
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 googlemapgoogle map sdk for ios
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]]
Or use the official apple mapMap 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
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>
As for the specific url and during, you can adjust them yourself. The one I set before seems to be 200 which is enough...
url
during
200
application is: if url can be opened, it will jump to the corresponding app
app
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.
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
Or use the official apple map
Map Links
So all you have to do is
Make an intermediate page, such as
redirect.html
and then addAs for the specific
The principle ofurl
andduring
, you can adjust them yourself. The one I set before seems to be200
which is enough...application is: if
url
can be opened, it will jump to the correspondingapp