获取手机的GPS位置 [英] Get GPS Location of Mobile Phone

查看:131
本文介绍了获取手机的GPS位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在环顾Google和SO,以便通过使用带有PHP的手机获取用户的GPS位置。不过,我唯一能找到的解决方案就是使用Javascript,而且我不想使用Javascript来做一些复杂的事情,只需在我现有的系统中添加一些PHP代码即可。



我的问题很简单:我怎样才能得到某人使用PHP浏览我的网站的GPS位置,而不是Javascript?



另外:
如果我必须使用Javascript,我如何从PHP访问价值?此外,有没有办法从这个GPS位置获取城市/国家,或者有可能获得城市/国家的另一种方法? 解决方案

您无法使用PHP获取GPS位置。



您可以使用GeoLocation来近似它(使用IP地址),但这是非常不可靠和最好的避免。

另一种选择是使用内置于HTML5的位置API。在访问您的网站时,会询问那些使用有能力的移动设备(或浏览器)是否由于功能原因而希望公开其位置,但是您不能强制用户泄露它:

 函数show_map(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
//让我们展示一张地图或做一些有趣的事情!
}

值得一读的示例指南/概览是这里(其中包括一个实时位置感知浏览如何工作的实例)。



位置信息在隐私方面是一个非常敏感的领域,因此手机制造商不会允许自动披露您要查找的信息。



更多阅读资源:




I have been looking around Google and SO for a way to get the GPS location of a user using a mobile phone with PHP. However, the only solutions I have found use Javascript, and I would rather not have to do some complicated stuff using Javascript when I can just add some PHP code to my already existing system.

My question is simple: How can I get the GPS location of somebody browsing my site with PHP, instead of Javascript?

Additionally: If I have to use Javascript, how can I access the value from PHP? Also, is there any way to get a city/country from this GPS location, or possibly another method to get the city/country?

解决方案

You can't get the GPS location using PHP.

You could use GeoLocation to approximate it (using the IP address), but this is notoriously unreliable and best avoided.

The other option is to use the location API built into HTML5. Upon visiting your site, those using a capable mobile device(or browser) will be asked if they wish to disclose their location for functional reasons, but you can't force users to divulge it:

function show_map(position) {
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;
  // let's show a map or do something interesting!
}

An example guide/overview worth reading is here (which includes a live example of how location-aware browsing works).

Location information is a very sensitive area with regard to privacy and thus handset manufacturers won't allow automatic disclosure of the information you're looking for.

Further reading resources:

这篇关于获取手机的GPS位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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