douba3378 2017-07-27 07:25
浏览 189

获取网络访问者的确切国家和城市(以drupal 8或PHP原生)

I need for my website to know the real and accurate location of a visitor to offer him / her near elements.

I am trying to consume various external services and they tell me that I am located in barcelona (when I l live in Madrid).

These are the services I am consuming:

Know any service or any way in PHP to get exact location data?

  • 写回答

2条回答 默认 最新

  • douqin6785 2017-08-01 06:46
    关注

    I am afraid this is not possible.

    The best way to go about solving this is to use javascript and get longitude and latitude from the visitor of your site. This, of course, requires the visitors device to have such abilities. Read more about this at MDN web docs.

    If your visitors device does not support this method, use IP Geo location as a fallback. The problem with this is that it is not reliable as you have discovered. I live near Bergen in Norway, and if I use IP to geolocate my phone, it always shows that I am in Oslo. This is due to my cell phone operator of course, but this is also a problem with other services giving you IP addresses. You can read more about how accurate IP Geo location is at WhatsMyIPAddress.com.

    Lastly, always give the user the ability to give you their location when visiting your site.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集