Baidu Map Open Platform Web Service API --Geocoding API (Geocoding and Reverse Geocoding)

   The api document address of Baidu Map Open Platform Geocoding Service and Reverse Geocoding Service: http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding

     Geocoding API is a class of interfaces used to provide conversion services from addresses to latitude and longitude coordinates or from latitude and longitude coordinates to addresses. Users can use C#, C++, Java and other development languages ​​to send requests and receive JSON and XML return data.

     Geocoding API has fully supported HTTP/HTTPS request forms.

Geocoding: that is, address resolution. Baidu latitude and longitude information is obtained from the structured address detailed to the street. For example, the address resolution result of "No. 27, Zhongguancun South Street, Haidian District, Beijing" is "lng:116.31985,lat:39.959836". At the same time, geocoding also supports the direct resolution of the names of places of interest and landmarks and landmark buildings to return Baidu's latitude and longitude. For example, the result of address resolution for "Baidu Building" is "lng:116.30815,lat:40.056885". For general POI retrieval requirements, it is recommended to use the Place API .

Reverse geocoding: that is, reverse address parsing, the structured address information is obtained from Baidu's latitude and longitude information, for example: "lat:31.325152,lng:120.558957" The result of reverse address parsing is "No. 318, Tayuan Road, Huqiu District, Suzhou City, Jiangsu Province" .

  Here is the PHP code used for testing:

<?php
	header("Content-type:text/html;charset=utf-8");
	// Baidu geocoding service
	$ak="SlKGotyLwOjjBUR2ZGb7uKAlO59FqHVY";
	$output="json";
	$callback="showLocation";
	$address="Chaoyang Square, Xingning District, Nanning";
	$city="Nanning";
	$url="http://api.map.baidu.com/geocoder/v2/?output=$output&address=$address&city=$city&ak=$ak";
	$res=getData($url);
	$res=json_decode($res,true);
	echo "<pre>";
	print_r($res);
	if($res['status']==0){
		// latitude and longitude
		$ lng = $ res ['result'] ['location'] ['lng'];
		$ lat = $ res ['result'] ['location'] ['lat'];
	}else{
		exit("Baidu geocoding service error, unable to get latitude and longitude!");
	}
	

	// Baidu reverse geocoding service
	$ak="SlKGotyLwOjjBUR2ZGb7uKAlO59FqHVY";
	$location=$lat.",".$lng;
	$output="json";
	$url="http://api.map.baidu.com/geocoder/v2/?location=$location&output=$output&ak=$ak";
	$data=getData($url);
	$data=json_decode($data,true);
	print_r($data);

	/*
	 * Use GET method to get the data of the specified URL
	 */
	function getData($url){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}
?>
The output of the webpage is as follows:
Array
(
    [status] => 0
    [result] => Array
        (
            [location] => Array
                (
                    [lng] => 108.32766625111
                    [years] => 22.825109768923
                )

            [precise] => 1
            [confidence] => 80
            [level] => UNKNOWN
        )

)

Array
(
    [status] => 0
    [result] => Array
        (
            [location] => Array
                (
                    [lng] => 108.32766625111
                    [years] => 22.825109774287
                )

            [formatted_address] => No. 236, Renmin East Road, Xingning District, Nanning City, Guangxi Zhuang Autonomous Region
            [business] => Chaoyang, District Industrial and Commercial Bureau, Longteng Road
            [addressComponent] => Array
                (
                    [country] => China
                    [country_code] => 0
                    [province] => Guangxi Zhuang Autonomous Region
                    [city] => Nanning City
                    [district] => Xingning District
                    [adcode] => 450102
                    [street] => Renmin East Road
                    [street_number] => 236号
                    [direction] => east
                    [distance] => 75
                )

            [pois] => Array
                (
                )

            [poiRegions] => Array
                (
                    [0] => Array
                        (
                            [direction_desc] => 内
                            [name] => Chaoyang Plaza
                            [tag] => leisure and entertainment
                        )

                )

            [sematic_description] => Inside Chaoyang Square
            [cityCode] => 261
        )

)


 
 
 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357178&siteId=291194637