dongqing8765 2016-07-02 07:09
浏览 90
已采纳

如何在我的网站上获取访客的经纬度? [重复]

This question already has an answer here:

I am researching ways of making ads actually relevant to people. How can I get the location of a visitor, who just loaded my page? I'm not talking IP Geo-location, I'm talking the exact latitude and longitude of a user, that I could later store in a database. Is there an API or something to allow me to get those values in PHP variables, using something like GPS?

</div>
  • 写回答

1条回答 默认 最新

  • douliang6563 2016-07-02 07:15
    关注

    First get visitor's location details from IP address

    How to get user IP Address in PHP

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    echo $ip;
    ?>
    

    How to get user/ visitor Location in PHP

    <?php
    require_once("userip/ip.codehelper.io.php");
    require_once("userip/php_fast_cache.php");
    
    $_ip = new ip_codehelper();
    
    $real_client_ip_address = $_ip->getRealIP();
    $visitor_location       = $_ip->getLocation($real_client_ip_address);
    
    $guest_ip   = $visitor_location['IP'];
    $guest_country = $visitor_location['CountryName'];
    $guest_city  = $visitor_location['CityName'];
    $guest_state = $visitor_location['RegionName'];
    
    echo "IP Address: ". $guest_ip. "<br/>";
    echo "Country: ". $guest_country. "<br/>";
    echo "State: ". $guest_state. "<br/>";
    echo "City: ". $guest_city. "<br/>";
    
    ?>
    

    For more detail kindly visit below link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错