使用百度地圖api實(shí)現(xiàn)根據(jù)地址查詢經(jīng)緯度
更新時(shí)間:2014年12月11日 09:21:28 投稿:hebedich
這篇文章主要介紹了使用百度地圖api實(shí)現(xiàn)根據(jù)地址查詢經(jīng)緯度的方法,附上實(shí)例,推薦給有需要的小伙伴們。
復(fù)制代碼 代碼如下:
<html xmlns=" <head>
<title>根據(jù)地址查詢經(jīng)緯度</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src=">
</head>
<body style="background:#CBE1FF">
<div style="width:730px;margin:auto;">
要查詢的地址:<input id="text_" type="text" value="徐州古彭廣場" 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("徐州", 12);
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>
以上就是代碼的全部內(nèi)容了,小伙伴們可以直接使用在項(xiàng)目中哦,不用跟我說謝謝,請叫我雷鋒大大~
相關(guān)文章
基于bootstrap實(shí)現(xiàn)廣告輪播帶圖片和文字效果
這篇文章主要介紹了基于bootstrap實(shí)現(xiàn)廣告輪播帶圖片和文字效果,效果非常棒,需要的朋友可以參考下2016-07-07js的各種排序算法實(shí)現(xiàn)(總結(jié))
下面小編就為大家?guī)硪黄猨s的各種排序算法實(shí)現(xiàn)(總結(jié))。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07JavaScript onclick與addEventListener使用的區(qū)別介紹
addEventListener()方法用于向指定元素添加事件句柄,使用 removeEventListener()方法來移除,onclick和addEventListener事件區(qū)別是:onclick事件會(huì)被覆蓋,而addEventListener可以先后運(yùn)行不會(huì)被覆蓋,addEventListener可以監(jiān)聽多個(gè)事件2022-09-09layui表格內(nèi)放置圖片,并點(diǎn)擊放大的實(shí)例
今天小編就為大家分享一篇layui表格內(nèi)放置圖片,并點(diǎn)擊放大的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09JavaScript實(shí)現(xiàn)防止網(wǎng)頁被嵌入Frame框架的代碼分享
這篇文章主要介紹了JavaScript實(shí)現(xiàn)防止網(wǎng)頁被嵌入Frame框架的代碼分享,本文給出了2種防嵌入方法,需要的朋友可以參考下2014-12-12