duanqiongdu9916 2019-02-26 18:51
浏览 777
已采纳

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

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.

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.

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?

  • 写回答

1条回答 默认 最新

  • dscqrkvr9562034621 2019-02-26 18:58
    关注

    You can try the geolocation 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

    According with Site Point: https://www.sitepoint.com/browser-geolocation/ this browsers have support.

    • Firefox 3.5+
    • Chrome 5.0+
    • Safari 5.0+
    • Opera 10.60+
    • Internet Explorer 9.0+
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序