当前位置:首页 > 开发 > Web前端 > 前端 > 正文

百度地图经纬度查询代码示例

发表于: 2012-11-28   作者:单眼皮小猪   来源:转载   浏览:
摘要: 前段时间研究百度地图,将研究的例子保存下,备用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="htt
前段时间研究百度地图,将研究的例子保存下,备用
<!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>
</html>

百度地图经纬度查询代码示例

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号