简体   繁体   English

获取当前用户所在的国家/地区而不是IP地址

[英]Get current country of user not with the IP address

I try to explain my problem: the customers of my site are usually tourists who book in advance from their country or last-minute when they are already here. 我试图解释我的问题:我网站的客户通常是游客,他们是从他们的国家/地区提前预订或在他们已经在这里的最后一刻预订的。 In order to offer last-minute offers to users who are already here and not to those who are at home I use a PHP script that recognizes the location via the IP address. 为了向已经在这里的用户而不是在家的用户提供最新的报价,我使用了一个PHP脚本,该脚本通过IP地址识别位置。

So far no problem, only that many users connected over mobile phone networks (roaming) have IP addresses assigned by their phone companies and located in their countries, so they will never see the offer I want to show them. 到目前为止,没有问题,只有许多通过移动电话网络(漫游)连接的用户拥有其电话公司分配的IP地址,并且位于他们的国家/地区,因此他们永远也看不到我要向他们展示的优惠。

I've already thought of inserting a script that asks for geolocation through their device, but I want to avoid this annoying request that many would not accept for obvious privacy issues. 我已经考虑过要插入一个脚本,要求通过其设备进行地理位置定位,但是我想避免这种令人讨厌的请求,因为许多人不会因为明显的隐私问题而接受该请求。 In short, it is always important to make navigation fast and pleasant to encourage confidence. 简而言之,快速,愉快地导航以激发信心一直很重要。

does anyone have a good suggestion? 有人有好的建议吗?

You can try the geolocation API. 您可以尝试使用地理位置API。

Just as an example... 举个例子...


if ("geolocation" in navigator) {
  navigator.geolocation.getCurrentPosition(function(position) {
     do_something(position.coords.latitude, position.coords.longitude);
   });
} else {
  /* geolocation IS NOT available */
}

reference from: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API 参考来自: https : //developer.mozilla.org/en-US/docs/Web/API/Geolocation_API

According with Site Point: https://www.sitepoint.com/browser-geolocation/ this browsers have support. 根据Site Point: https//www.sitepoint.com/browser-geolocation/此浏览器具有支持。

  • Firefox 3.5+ Firefox 3.5+
  • Chrome 5.0+ Chrome 5.0以上版本
  • Safari 5.0+ Safari 5.0+
  • Opera 10.60+ Opera 10.60+
  • Internet Explorer 9.0+ Internet Explorer 9.0以上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM