正文 1929字数 462,478阅读

根据经纬度找到具体地址: http://api.map.baidu.com/geocoder?location=纬度,经度&output=输出格式类型&key=用户密钥 如: http://api.map.baidu.com/geocoder?location=31.407452,121.490523&output=json&key=6eea93095ae93db2c77be9ac910ff311 根据具体地址找到经纬度: http://api.map.baidu.com/geocoder?address=地址&output=输出格式类型&key=用户密钥&city=城市名 如: http://api.map.baidu.com/geocoder?address=牡丹江路营业厅&output=json&key=6eea93095ae93db2c77be9ac910ff311&city=上海市
Run code
Cut to clipboard


    php
    <?php function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page 返回网页 CURLOPT_HEADER => false, // 不返回头信息 CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // 设置UserAgent CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect 连接超时 CURLOPT_TIMEOUT => 120, // timeout on response 回复超时 CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } $address='南宁市中山路66号金外滩商务大厦1301'; $n=get_web_page('http://api.map.baidu.com/geocoder?address='.$address.'&output=json'); $n=$n['content']; $n=json_decode($n,true);//强制json_decode结果转换为数组 //$n=$n->location(); print_r($n['result']['location']); ?>
    Run code
    Cut to clipboard