zoukankan      html  css  js  c++  java
  • php Thinkphp 经纬度查位置(误差200米左右)

    /**
     * # +========================================================================
     * # | - @name        获取位置
     * # | - @author     cq <just_leaf@foxmail.com> 
     * # | - @copyright zmtek 2018-11-07
     * # +------------------------------------------------------------------------
     * # | - 1首页
     * # +========================================================================
     */
    function getaddr($lng,$lat) {
        
        // http://www.gpsspg.com/maps.htm
        $result = file_get_contents('https://apis.map.qq.com/jsapi?qt=rgeoc&lnglat='.$lng.'%2C'.$lat.'&key=FBOBZ-VODWU-C7SVF-B2BDI-UK3JE-YBFUS&output=jsonp&pf=jsapi&ref=jsapi&cb=qq.maps._svcb3.geocoder0');
        $str     = explode('qq.maps._svcb3.geocoder0&&qq.maps._svcb3.geocoder0(',$result)[1];
        $text     = substr($str,0,strlen($str)-1);
        $pat     = '#"addr"(?<data>.*)","addr_info"#';
        preg_match($pat,$text,$mat);
        $str     = substr($mat[0],8,100);
        $addr     = explode('","addr_info":',$str)[0];
        $addr   = characet($addr);
        return $addr;
    }
    
    /**
     * # +========================================================================
     * # | - @name        转码utf8
     * # | - @author     cq <just_leaf@foxmail.com> 
     * # | - @copyright zmtek 2018-11-07
     * # +------------------------------------------------------------------------
     * # | - 1首页
     * # +========================================================================
     */
    function characet($data){
        
        if( !empty($data) ){
            $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
            
            if( $fileType != 'UTF-8'){
                
                $data = mb_convert_encoding($data ,'utf-8' , $fileType);
            }
        }
      return $data;
    }
  • 相关阅读:
    中国剩余定理(CRT) & 扩展中国剩余定理(ExCRT)总结
    各种求逆元
    A*(A_star)搜索总结
    线段树总结
    C++的STL
    Unable to make the session state request to the session state server处理方法
    判断UserAgent是否来自微信
    VS2010 EntityFramework Database First
    VS2010类似Eclipse文件查找功能-定位到
    Newtonsoft.Json随手记
  • 原文地址:https://www.cnblogs.com/leaf-cq/p/11715538.html
Copyright © 2011-2022 走看看