• 根据经纬度查询当前地点,百度google接口


    <?php   

        /** 百度 API   -----根据经纬度查询当前地点  **/  
        header("Content-Type: text/html; charset=UTF-8");
        function getBaiduAPIAddress($lat,$lng){  //纬度,经度
            $location = $lat.','.$lng;  
            $url = 'http://api.map.baidu.com/geocoder/v2/?location='.$location.'&output=json&pois=0&ak=OFQT011raLmgaOO1bNVvxLup';
            $ch = curl_init();  
            curl_setopt($ch, CURLOPT_URL, $url);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
            curl_setopt($ch, CURLOPT_HEADER, 0);  
            $data = curl_exec($ch);  
            curl_close($ch);  
            $data = json_decode($data,true);
            $city = $data['result']['addressComponent']['city'];  
            echo $city;  
        }  
        //getBaiduAPIAddress(30.521966,112.333905);
        //echo "<br />";

        /**  Google API  根据经纬度查询当前地点 **/
        function getGoogleAPIAddress($lat,$lng){  //纬度,经度
            $location = $lat.','.$lng;  
            $url = 'http://maps.google.cn/maps/api/geocode/json?latlng='.$location.'&language=zh';
            $ch = curl_init();  
            curl_setopt($ch, CURLOPT_URL, $url);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
            curl_setopt($ch, CURLOPT_HEADER, 0);  
            $data = curl_exec($ch);  
            curl_close($ch);  
            $data = json_decode($data,true);
            $city = $data['results']['0']['address_components']['2']['long_name'];  
            echo $city;  
        }  
        //getGoogleAPIAddress(30.521966,112.333905);

        function getBaiduAPIWeather($location){  //天气预报
            $url = 'http://api.map.baidu.com/telematics/v3/weather?location='.$location.'&output=json&ak=OFQT011raLmgaOO1bNVvxLup';
            $ch = curl_init();  
            curl_setopt($ch, CURLOPT_URL, $url);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
            curl_setopt($ch, CURLOPT_HEADER, 0);  
            $data = curl_exec($ch);  
            curl_close($ch);  
            $data = json_decode($data,true);
            $weather = $data['results']['0']['weather_data'];
            echo "<pre />";
            print_r($weather);
        }
        //getBaiduAPIWeather("上海");
    ?>

  • 相关阅读:
    LeetCode#1047-Remove All Adjacent Duplicates In String-删除字符串中的所有相邻重复项
    LeetCode#345-Reverse Vowels of a String-反转字符串中的元音字母
    LeetCode#344-Reverse String-反转字符串
    LeetCode#232-Implement Queue using Stacks-用栈实现队列
    LeetCode#225-Implement Stack using Queues-用队列实现栈
    LeetCode#20-Valid Parentheses-有效的括号
    树的遍历
    [leetcode] 树(Ⅰ)
    二叉树图形化显示
    你错在成长于文明的边陲
  • 原文地址:https://www.cnblogs.com/DellHome/p/6564486.html
Copyright © 2020-2023  润新知