从Android和iPhone使用默认的启动位置,用浏览器打开谷歌地图应用程序 [英] open google maps app from a browser with default start location on android and iphone

查看:169
本文介绍了从Android和iPhone使用默认的启动位置,用浏览器打开谷歌地图应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个移动网站,我有一个可以打开谷歌地图在iPhone本机应用程序,并通过使用链接的格式用的android默认的开始和结束位置的链接:<一href="http://maps.google.com/maps?saddr=XX&daddr=XX">http://maps.google.com/maps?saddr=XX&daddr=XX.

I have a mobile site and I have a link that can open the google maps native app on iphone and android with default start and end locations by using the link format: http://maps.google.com/maps?saddr=XX&daddr=XX.

我的问题是,我希望能够设置起始位置为当前的位置,我希望它来自Android和iPhone浏览器。从我的经验,如果我离开了SADDR空白,在Android的这一默认为当前的位置,但在iPhone上它只是离开起始位置的空白。如果我设置了SADDR为当前位置,这是设置起始位置为当前位置上的iPhone,但在Android上不承认的位置。

My problem is, I want to be able to set the starting location to be the current location, and I want it to work from both android and iphone browsers. From my experience, if I leave the saddr blank, in android this defaults to the current location but on iphone it just leaves the start location blank. If I set the saddr to "current location", this sets the start location to be the current location on iphone but on android it doesn't recognize the location.

我的解决办法,现在是使用用户的地理纬度/经度坐标的起始地址。这成功地工作在两个平台间,但根据用于获取坐标的方法中,可能不一样精确从该应用的全球定位系统的用户的当前位置。我想知道是否有办法让链接与正确的当前位置为起点,开启本机应用程序。我知道我也可以有条件地检查用户代理,并创建相应的链接,但我希望会有一个更优雅的方式来做到这一点。

My solution right now is to use the user's geo lat/long coordinates as the start address. This works successfully across both platforms but depending on the method used to get the coordinates, it may not be as accurate as the user's current location from the gps on the app. I was wondering if there was some way to get the link to open the native app with the correct "current location" for the starting point. I know I could also conditionally check for the user-agent and create the link accordingly but I was hoping that there would be a more elegant way to do this.

推荐答案

我只是替换以下字符串我的起点和目的地的LNG /纬度值

I simply replace the values in the following string with my start and destination Lng/Lat

http://maps.google.com/maps?saddr=START_ADD&amp;daddr=DEST_ADD&amp;ll=START_ADD

然后,我启动URL像这样的机器人,这将让用户选择使用浏览器或本民族的地图应用程序:

Then I launch the url like this in android, which will let the user choose to either use the browser or their native maps app:

String url = "http://maps.google.com/maps?saddr=START_ADD&amp;daddr=DEST_ADD&amp;ll=START_ADD";

startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)));  

有关iOS的,如果你preFIX URL以地图://,而不是http://,将推出它的作品真的很好在手机上的地图应用程序。类似于

For iOS, if you prefix the url with maps:// instead of http:// it will launch the maps application on the phone which works really well. Something like

NSString *url = @"maps://maps.google.com/maps?saddr=START_ADD&amp;daddr=DEST_ADD&amp;ll=START_ADD";

[[UIApplication sharedApplication] openURL:[NSURL urlWithString:url]];

这是我选择来处理它的方式。它的pretty的轻松无论是设备上的当前LNG /纬度利用各自的位置的框架来获得。结果似乎总是pretty的准确的给我,好了,你可以在任何你想要的结果如何精确指定。更准确,你的电池更漏,有时需要更长的时间来获得,但是这通常你到底调整得到您实现最佳效果的东西。

That is the way I have chosen to handle it. Its pretty easy on either device to get the current Lng/Lat using their respective location frameworks. The results always seem pretty accurate to me as well, you can specify in either how accurate you want the results. The more accurate, the more drain on your battery and sometimes it takes longer to acquire but that's usually something you tweak in the end to get the best results for your implementation.

这篇关于从Android和iPhone使用默认的启动位置,用浏览器打开谷歌地图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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