<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="./jquery-1.4.2.min.js"></script>
<!-- 这里的引用有ak和没有ak的区别暂时还没有弄清楚
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Wb3W4PL5khQp9GS6Gm6HIdW7"></script>
-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0"></script>
<script type="text/javascript">
function test1(){
//112.881885, 28.220368
var la = $("#la").val();
var lo = $("#lo").val();
if(la==""||lo==""){
alert("经纬度都不能为空!");
return;
}
//alert(la+","+lo);
var gc = new BMap.Geocoder();
var map = new BMap.Map("container");
var pt = new BMap.Point(la, lo);
gc.getLocation(pt, function(rs){
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
}
</script>
</head>
<body>
<center>
<div style="margin-top:100px">
测试用例:经度:112.881885,纬度:28.220368;地址:湖南省, 长沙市, 岳麓区, 谷苑路, 186号
<br/><br/><br/>
经度:<input type="text" id="la" value="112.881885"/>
纬度:<input type="text" id="lo" value="28.220368"/>
<input type="button" id="test" onclick="test1();" value="点我获取位置"/>
</div>
</center>
</body>
</html>