Code example for calling the latitude/longitude conversion interface: php-based code example for calling the latitude/longitude conversion interface
// + Response // ------------------------------------ // sample code for calling the resolution of latitude and longitude addresses-aggregate data // online interface documentation: http://www.juhe.cn/docs/15//----------------------------------header ('Content-type: text/html; charset = utf-8 '); // Configure Your applied appkey $ appkey = "*********************"; // ************* 1. latitude and longitude address resolution *********** $ url =" http://apis.juhe.cn/geo/ "; $ Params = array (" lng "=>" ", // longitude (for example, 119.9772857)" lat "=>" ", // latitude (for example: 27.327578) "key" => $ appkey, // applied APPKEY "type" => "", // transfer coordinate type, 1: GPS 2: Baidu longitude and latitude 3: google longitude and latitude "dtype" => "", // return data format: json or xml, default json); $ paramstring = http_build_query ($ params ); $ content = juhecurl ($ url, $ paramstring); $ result = json_decode ($ content, true); if ($ result) {if ($ result ['error _ Code'] = '0') {print_r ($ result);} else {echo $ result ['error _ Code']. ":". $ re Sult ['reason '] ;}} else {echo "request failed ";} //************************************** * ***********/***** request interface returned content * @ param string $ url [requested URL] * @ param string $ params [request parameter] * @ param int $ ipost [whether to use the POST form] * @ return string */function juhecurl ($ url, $ params = false, $ ispost = 0) {$ httpInfo = array (); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt ($ ch, CURLOPT_US ERAGENT, 'juhedata'); curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt ($ ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); if ($ ispost) {curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ params ); curl_setopt ($ ch, CURLOPT_URL, $ url);} else {if ($ params) {curl_setopt ($ ch, C URLOPT_URL, $ url .'? '. $ Params);} else {curl_setopt ($ ch, CURLOPT_URL, $ url) ;}}$ response = curl_exec ($ ch); if ($ response === FALSE) {// echo "cURL Error :". curl_error ($ ch); return false;} $ httpCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); $ httpInfo = array_merge ($ httpInfo, curl_getinfo ($ ch )); curl_close ($ ch); return $ response ;}