您的位置:首页 > 编程语言

百度地图搜索经纬度代码

2016-07-08 21:49 330 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百度地图API演示:查询百度地图经纬度</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?key=3690f5facff0a96fc7ff291c20f532e0&v=1.0&services=true" ></script>
<script type="text/javascript">

function MblogDotccMap(keyword){
var map = new BMap.Map("MblogMap");          // 创建地图实例
var point = new BMap.Point(119.607568,39.940628);  // 创建点坐标

map.centerAndZoom(point, 17);                 // 初始化地图,设置中心点坐标和地图级别

//添加缩放控件
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.ScaleControl());
map.addControl(new BMap.OverviewMapControl());

/*显示地图中心地点的坐标
map.addEventListener("dragend", function(){
//map.panTo(point);
var center = map.getCenter();
document.getElementById("info").innerHTML = "当前地图中心坐标:" + center.lng + ", " + center.lat;
});*/

//搜索
var local = new BMap.LocalSearch(map, {renderOptions: {map: map, panel: "results_info"}});
map.panBy(point);
local.search(keyword);
local.getResults();
local.setSearchCompleteCallback(function(searchResult){
var poi = searchResult.getPoi(0);
//alert(poi.point.lng+"   "+poi.point.lat);
document.getElementById("info1").value = poi.point.lng + "," + poi.point.lat;
});

map.addEventListener("click", function (e) {
var _point = e.point;
document.getElementById("info2").value = _point.lng + "," + _point.lat;

});

}

</script>
</head>
<body onload="MblogDotccMap();" onkeydown="if(event.keyCode==13)MblogDotccMap(document.getElementById('keyword').value)">
<div style="width:600px;height:450px;border:1px solid gray; float:left" id="MblogMap"></div>
<div style="margin-top:10px; margin-left:10px; float:left">
先用搜索查询出大概位置,然后鼠标点击想要的具体位置:
<div id="search" style="margin-top:10px; margin-left:10px;">搜索:
<input type="text" size="20" name="keyword" id="keyword" />
<input type="submit" value="提交" onclick="MblogDotccMap(document.getElementById('keyword').value)" />
</div>
<div id="results_info" style="margin-top:10px; margin-left:10px;"></div>
<div id="info" style="margin-top:10px; margin-left:10px;">
搜索地址经纬度:<input type="text" id="info1"/><br/>
鼠标点击经纬度:<input type="text" id="info2"/>
</div>

</div>
</body>


百度地图API演示:查询百度地图经纬度
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: