【问题标题】:How can i know the location of a user我如何知道用户的位置
【发布时间】:2016-10-20 10:21:15
【问题描述】:

如果可以的话,我会尝试检测用户的确切位置,尤其是街道。

我尝试使用 IP 但这对我不起作用,因为它没有给出我想要的确切位置示例是 Lebanon Beirut Azarieh 或Lebanon Beirut ABC Achrafieh 并且我想使用 PHP 将此位置存储在 MYSQL 数据库表中。

我试过这个代码here 此代码在 Firefox 中的 Localhost 上提供了一个很好的位置

但 Firefox 和 Google chrome 上的 Online 显示您的位置:不可用

它也不适用于手机浏览器 iPhone 和 android (safari,chrome,...)

这个想法是公司的用户想在他的手机上使用该网站,当他使用该网站时,我想在此获取街道的确切位置并将其存储在数据库中

【问题讨论】:

  • IP Geo 数据是粗略估计,一些 IP Geo 记录不准确。要获得准确/更准确的位置,这将需要 GPS 许可,因此客户端必须允许/授予您的站点/应用程序使用客户端 GPS 的权限。

标签: javascript php mysql


【解决方案1】:

您可以使用标志,enableHighAccuracy:true

这是一个示例代码:

$(document).ready(function($){
  if (navigator.geolocation){
      navigator.geolocation.getCurrentPosition(function(position){
        latitude = position.coords.latitude;
        longitude = position.coords.longitude;
          //alert('latitude: '+latitude+' longitude: '+longitude);
      }, function(error) {
          alert('Error occurred. Error code: ' + error.code);
      },{timeout:20000,enableHighAccuracy: true});
  }
  else{
    alert('no geolocation support');
  }
});

我还想引用 enableHighAccuracy 取决于设备。

参考here

【讨论】:

    【解决方案2】:

    这是一个android代码链接,你可以从getlocation with street得到一些想法

    【讨论】:

    • 但这不是应用程序,这是一个网站
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多