码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-03-17 11:09:05      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:amp   atl   htm   long   经纬   查询   etop   经纬度   tput   

<?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("上海");
?>

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

标签:amp   atl   htm   long   经纬   查询   etop   经纬度   tput   

原文地址:http://www.cnblogs.com/DellHome/p/6564486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!