根據輸入地址獲得經緯度


<html xmlns="http://www.w3.org/1999/xhtml">  

<head>
<title>根據地址查詢經緯度</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
</head>
<style>
body{
background:#CBE1FF;margin:0;padding:0;
}
.con{
height: 70px;
width: 480px;
}
.btn{
height: 70px;
width: 100px
}
*{
font-size: 30px
}
#container{
position: absolute;margin-top:220px;width: 100%;height: 84%;top: 50;left:0;border: 1px solid gray;overflow:hidden;
}
#ok{
display: inline-block;
background: #F1F1F1;
text-align: center;
line-height:70px;
border: 1px solid #A9A9A9;
text-decoration: none;
color: black;
}
#find{
margin-left:8px;

}
</style>

<body>
<br>
<div>&emsp; &emsp;
要查詢的地址:
<input id="text_" class="con" placeholder="請輸入地址" type="text" value=""/>&emsp;
<input type="button" class="btn" id="find" value="查詢" onclick="searchByStationName();" /> &emsp;
<br>
<br>
&emsp;查詢結果(經緯度):
<input id="result_" class="con" type="text" /> &emsp;
<a href="http://192.168.200.127:8088/WeChat/views/wechato.html?code=011sZSUH0zqjkh2C9KTH0DrgVH0sZSUp" class="btn" id="ok">確定</a> &emsp;

<div id="container">
</div>
</div>
</body>




<script type="text/javascript">
var map = new BMap.Map("container");
map.centerAndZoom("深圳", 15);
map.enableScrollWheelZoom(); //啟用滾輪放大縮小,默認禁用
map.enableContinuousZoom(); //啟用地圖慣性拖拽,默認禁用

map.addControl(new BMap.NavigationControl()); //添加默認縮放平移控件
map.addControl(new BMap.OverviewMapControl()); //添加默認縮略地圖控件
map.addControl(new BMap.OverviewMapControl({
isOpen: true,
anchor: BMAP_ANCHOR_BOTTOM_RIGHT
})); //右下角,打開

var localSearch = new BMap.LocalSearch(map);
localSearch.enableAutoViewport(); //允許自動調節窗體大小
function searchByStationName() {
map.clearOverlays(); //清空原來的標注
var keyword = document.getElementById("text_").value;
localSearch.setSearchCompleteCallback(function(searchResult) {
var poi = searchResult.getPoi(0);
document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
map.centerAndZoom(poi.point, 13);
var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 創建標注,為要查詢的地方對應的經緯度
map.addOverlay(marker);
var content = document.getElementById("text_").value + "<br/><br/>經度:" + poi.point.lng + "<br/>緯度:" + poi.point.lat;

var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
marker.addEventListener("click", function() {
this.openInfoWindow(infoWindow);
});
// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳動的動畫
});
localSearch.search(keyword);
}

$("#ok").onclick = function(){
window.location.href = "";
}


</script>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM