Php-based map coordinate service interface call code instance php code
// + ---------------------------------------------------------------------- // ------------------------------ // Sample code for calling the map coordinate service-aggregate data // online interface documentation: http://www.juhe.cn/docs/32//---------------------------------- Header ('content-type: text/html; charset = utf-8 '); // Configure Your applied appkey $ appkey = "*********************"; // ************* 1. latitude and longitude conversion *********** $ url =" http://v.juhe.cn/offset/index "; $ Params = array (" lng "=>" ", // longitude, for example, 116.3974965092" lat "=>" ", // latitude, such: 39.908700982285396 "type" => "", // conversion type, 1: GPS-> Baidu, 2: Baidu-> GPS, 3: GPS-> Google, 4: google-> GPS 5: Baidu-> Google, 6: Google-> Baidu "dtype" => "", // the returned data format is json, xml, or jsonp, the default json "callback" => "", // when the return format is jsonp, you must pass "key" => $ appkey, // The key you applied ); $ 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']. ":". $ result ['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, timeout); curl_setopt ($ ch, CURLOPT_USERAGENT, '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, CU RLOPT_POSTFIELDS, $ params); curl_setopt ($ ch, CURLOPT_URL, $ url);} else {if ($ params) {curl_setopt ($ ch, CURLOPT_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 ;}