百度地图实现地址解析:

百度地图实现地址解析:

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>

地址解析</title>

<script type="text/javascript" src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194&v=1.1&services=true">

</script>

</head>

<body>

<div style="width:1000px;height:550px;border:1px solid gray" id="container">

</div>

city:<input type="text" size="50" id="city"><br>

address:<input type="text" size="50" id="address">

<input type="button" onclick="geoCode()" value="搜索">

</body>

</html>

<script type="text/javascript">

var map = new BMap.Map("container");

map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);

// 创建地址解析器实例

var myGeo = new BMap.Geocoder();

// 将地址解析结果显示在地图上,并调整地图视野

function geoCode(){

var address = document.getElementById("address").value;

var city = document.getElementById("city").value;

	myGeo.getPoint(address, function(point){

	  if (point) {

	  alert(point.lng+","+point.lat);

	    map.centerAndZoom(point, 16);

	    map.addOverlay(new BMap.Marker(point));

	  }

	},city);

}

</script>





 

 

你可能感兴趣的:(百度地图)