利用百度API獲取地址經緯度
一、調用百度地圖,在當前頁面彈窗,搜索地址,右鍵獲取地址經緯度
引入文件如下:
<script type="text/javascript" src="http://api.map.baidu.com/此處是百度api需要申請"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/MarkerTool/1.2/src/MarkerTool_min.js"></script>
<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="./twitter.css" />
<script type="text/javascript" src="./jquery.artDialog.js?skin=twitter"></script>
<script type="text/javascript" src="./jquery-2.2.3.min.js"></script>
HTML代碼如下:
<div >
<label>
地圖標註<span style="color: #FF0000;">*</span>
</label>
<br/>
<a class="pri" href="./biaozhumap.html" style="float:left;color:red;border:1px solid #ccc;padding:3px;border-radius:3px;">點擊添加經緯度</a>
</div>
<div>
<label>
經度<span style="color: #FF0000;">*</span>
</label>
<input type="text" id="lng" onFocus="this.blur()" nullmsg="請填寫經度" name="longitude">
</div>
<div>
<label>
緯度<span style="color: #FF0000;">*</span>
</label>
<input type="text" id="lat" onFocus="this.blur()" placeholder="(必填)" nullmsg="請填寫緯度" name="latitude">
</div>
JS代碼如下:
<script>
//標註地圖
$(document).on('click', '.pri', function () {
var aurl = "./biaozhumap.html";
var atext = '標註商家地址';
var id = 'id=' + $(this).attr('id');
window.mapid = $(this).attr('id');
window.point = $(this).attr('point') || "";
window.art_id = art.dialog({id: 'art_id',
width: 800,
height: 550,
marginLeft: 260,
top: 50,
title: atext,
lock: true
});
$.ajax({
data: id,
url: aurl,
type: 'post',
success: function (data) {
art_id.content(data);
},
cache: true
});
return false;
});
function setpoint(x, y) {
$("#lng").val(x);
$("#lat").val(y);
window.art_id.close();
}
</script>
圖例: