根据经纬度找到具体地址:
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=上海市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']);
?>
判断点是否在多边形内:
可以使用方法:
BMapLib.GeoUtils.isPointInPolygon(point, polygon) Boolean
判断点是否多边形内
例子:
var _ppoints = [
new BMap.Point(120.220588,30.26135),
new BMap.Point(120.218863,30.258449),
new BMap.Point(120.222618,30.256702),
new BMap.Point(120.224748,30.25926),
new BMap.Point(120.220588,30.26135)];
var pppoint = new BMap.Point(120.222043,30.259197);
var result = BMapLib.GeoUtils.isPointInPolygon(pppoint, _ppolygon);
alert("result:"+result);
返回结果为 true;
另外我查找api ,判断一个点是否在可视范围内,
BMapLib.GeoUtils.isPointInRect(point, bounds) Boolean
判断点是否在矩形内
不管我怎么调,都是报错,报lng不存在,请遇到类似问题的兄弟指点一下。