全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
12
返回列表 发新帖
楼主: xiaohei
打印 上一主题 下一主题

高精度IP地图定位什么原理?

[复制链接]
11#
发表于 2020-7-8 15:43:13 | 只看该作者
基站定位+数据分析
12#
发表于 2020-7-8 15:43:29 | 只看该作者
气压计有点用?
13#
发表于 2020-7-8 15:48:20 | 只看该作者
示例:
http://blog.iytc.net/tools/map.php

  1. <?php
  2. /**
  3. * 根据地理坐标获取国家、省份、城市,及周边数据类(利用百度Geocoding API实现)
  4. * 百度密钥获取方法:http://lbsyun.baidu.com/apiconsole/key?application=key(需要先注册百度开发者账号)

  5. *
  6. * Func:
  7. * Public  locationByGPS    根据GPS地址获取国家、省份、城市及周边数据
  8. * Public  locationByIP     根据IP地址获取国家、省份、城市及周边数据
  9. * Public  locationByNAME  根据地址名称获取国家、省份、城市及周边数据
  10. * Private toCurl              使用curl调用百度Geocoding API
  11. */

  12. class Geocoding {

  13.     // 百度Geocoding API
  14.     const API = 'http://api.map.baidu.com/geocoder/v2/';

  15.     // 不显示周边数据
  16.     const NO_POIS = 0;

  17.     // 显示周边数据
  18.     const POIS = 1;

  19.     /**
  20.      * 根据地址获取国家、省份、城市及周边数据
  21.      * @param  String  $ak        百度ak(密钥)
  22.      * @param  Decimal $longitude 经度
  23.      * @param  Decimal $latitude  纬度
  24.      * @param  Int     $pois      是否显示周边数据
  25.      * @return Array
  26.      */
  27.     public static function locationByGPS($ak, $longitude, $latitude, $pois=self::NO_POIS){

  28.         $param = array(
  29.                 'ak' => $ak,
  30.                 'location' => implode(',', array($latitude, $longitude)),
  31.                 'pois' => $pois,
  32.                 'output' => 'json'
  33.         );

  34.         // 请求百度api
  35.         $response = self::toCurl(self::API, $param);

  36.         $result = array();

  37.         if($response){
  38.             $result = json_decode($response, true);
  39.         }

  40.         return $result;

  41.     }

  42.     public static function locationByNAME($ak, $name, $pois=self::NO_POIS){

  43.         $param = array(
  44.                 'ak' => $ak,
  45.                 'address' => str_replace(' ','+',$name),
  46.                 'pois' => $pois,
  47.                 'output' => 'json'
  48.         );

  49.         // 请求百度api
  50.         $response = self::toCurl(self::API, $param);

  51.         $result = array();

  52.         if($response){
  53.             $result = json_decode($response, true);
  54.         }

  55.         return $result;

  56.     }

  57. public function locationByIP($ak,$ip, $pois=self::NO_POIS)
  58. {
  59.   //检查是否合法IP
  60.   if (!filter_var($ip, FILTER_VALIDATE_IP))
  61.   {
  62.    throw new Exception('ip地址不合法');
  63.   }
  64.   $param = array(
  65.     'ak' => $ak,
  66.     'ip' => $ip,
  67.     'pois' => $pois,
  68.     'coor' => 'bd09ll'//百度地图GPS坐标
  69.   );
  70.   $api = 'http://api.map.baidu.com/location/ip';


  71.       // 请求百度api
  72.         $response = self::toCurl($api, $param);

  73.         $result = array();

  74.         if($response){
  75.             $result = json_decode($response, true);
  76.         }

  77.         return $result;


  78. }

  79.     /**
  80.      * 使用curl调用百度Geocoding API
  81.      * @param  String $url    请求的地址
  82.      * @param  Array  $param  请求的参数
  83.      * @return JSON
  84.      */
  85.     private static function toCurl($url, $param=array()){

  86.         $ch = curl_init();

  87.         if(substr($url,0,5)=='https'){
  88.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
  89.             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在
  90.         }

  91.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  92.         curl_setopt($ch, CURLOPT_URL, $url);
  93.         curl_setopt($ch, CURLOPT_POST, true);
  94.         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));

  95.         $response = curl_exec($ch);

  96.         if($error=curl_error($ch)){
  97.             return false;
  98.         }

  99.         curl_close($ch);

  100.         return $response;

  101.     }

  102. }


  103.  
  104. ?>
复制代码
14#
发表于 2020-7-8 15:51:26 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
15#
发表于 2020-7-8 16:08:47 | 只看该作者
abccba94 发表于 2020-7-8 15:48
示例:
http://blog.iytc.net/tools/map.php

误差有点大啊,哈哈哈
16#
发表于 2020-7-8 16:16:59 | 只看该作者
abccba94 发表于 2020-7-8 15:48
示例:
http://blog.iytc.net/tools/map.php

还不错,我这测到跨了两条街
17#
发表于 2020-7-8 16:18:09 | 只看该作者
精度随缘呗 那还能咋办
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-12 10:01 , Processed in 0.059599 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表