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;
    }
  • 相关阅读:
    Scanner类
    每日总结-05-17
    栈的基本操作 出栈与入栈
    Angularjs1.x 项目结构
    【树形dp小练】HDU1520 HDU2196 HDU1561 HDU3534
    [ACM] hdu 1251 统计难题 (字典树)
    Asakura的魔法世界
    distcp导致个别datanode节点数据存储严重不均衡分析
    Redis集群主备模式部署
    java的输入输出流(一)
  • 原文地址:https://www.cnblogs.com/leaf-cq/p/11715538.html
Copyright © 2011-2022 走看看