<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" οnclick="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>
百度地图api-根据地区名称反查其经纬度的实例
最新推荐文章于 2020-12-03 20:31:11 发布