百度地圖API + js 將地址轉(zhuǎn)為經(jīng)緯度

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

??<head>

????<title>根據(jù)地址查詢經(jīng)緯度</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>

??<body?style="background:#CBE1FF">

????<div?style="width:730px;margin:auto;">

??????要查詢的地址:<input?id="text_"?type="text"?value="鄭州大學(xué)"?style="margin-right:100px;"?/>?查詢結(jié)果(經(jīng)緯度):

??????<input?id="result_"?type="text"?/>

??????<input?type="button"?value="查詢"?onclick="searchByStationName();"?/>

??????<div?id="container"?style="position:?absolute;

????margin-top:30px;

????width:?730px;

????height:?590px;

????top:?50;

????border:?1px?solid?gray;

????overflow:hidden;">

??????</div>

????</div>

??</body>

??<script?type="text/javascript">

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

????map.centerAndZoom("鄭州",?15);

????map.enableScrollWheelZoom();?//啟用滾輪放大縮小,默認(rèn)禁用

????map.enableContinuousZoom();?//啟用地圖慣性拖拽,默認(rèn)禁用

????map.addControl(new?BMap.NavigationControl());?//添加默認(rèn)縮放平移控件

????map.addControl(new?BMap.OverviewMapControl());?//添加默認(rèn)縮略地圖控件

????map.addControl(new?BMap.OverviewMapControl({

??????isOpen:?true,

??????anchor:?BMAP_ANCHOR_BOTTOM_RIGHT

????}));?//右下角,打開

????var?localSearch?=?new?BMap.LocalSearch(map);

????localSearch.enableAutoViewport();?//允許自動(dòng)調(diào)節(jié)窗體大小

????function?searchByStationName()?{

??????map.clearOverlays();?//清空原來的標(biāo)注

??????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));?//?創(chuàng)建標(biāo)注,為要查詢的地方對應(yīng)的經(jīng)緯度

????????map.addOverlay(marker);

????????var?content?=?document.getElementById("text_").value?+?"<br/><br/>經(jīng)度:"?+?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);?//跳動(dòng)的動(dòng)畫

??????});

??????localSearch.search(keyword);

????}

??</script>

</html>

//非原創(chuàng),出處在云端,

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容