现在的位置: 首页 > 综合 > 正文

百度地图api-根据地区名称反查其经纬度的实例

2012年11月25日 ⁄ 综合 ⁄ 共 922字 ⁄ 字号 评论关闭

<html>
<head>
<meta http-equiv="Content-Type" content="text ml; charset=utf-8">
<title></title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3" ></script>
</head>
<body>
<div style="position:absolute;width:730px;height:590px;top:50;left:0;border:1px solid gray;overflow-y:hidden;" id="container"></div>
<input id="text_" type="text" value="上海"/>
<input type="button" value="search" onclick="searchByStationName();">
</body>
<script>
var map = new BMap.Map("container");
map.centerAndZoom("北京", 6);

var localSearch= new BMap.LocalSearch (map, {
renderOptions: {
pageCapacity: 8,
autoViewport: true,
selectFirstResult: false
}
});

localSearch.enableAutoViewport();
function searchByStationName()
{

var keyword = document.getElementById("text_").value;
localSearch.setSearchCompleteCallback(function(searchResult){
var poi = searchResult.getPoi(0);
alert(poi.point.lng+" "+poi.point.lat);
map.centerAndZoom(poi.point, 8);
});
localSearch.search(keyword);

}
</script>
</html>

抱歉!评论已关闭.