|
楼主 |
发表于 2016-5-16 13:23:33
|
显示全部楼层
html文件:
========================================================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=1d4adf2a0770814d3b5386dc84eac6c8&plugin=AMap.Geocoder"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript" src="../system/lib/jquery/jquery-1.11.1.js"></script>
<title>机构位置确认</title>
</head>
<body>
<div id="container"></div>
<div id="tip">
<span id="result" style="font-size: 12px;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;">
<span id="adressId"></span> : (<span id="LngId"></span>,<span id="LatId"></span>)
</span>
</div>
<script language="javascript">
var map = new AMap.Map("container", {
resizeEnable: true
});
//取传进来的地址信息
$(window).on('message',function(message){
var orgAddress = message.originalEvent.data;
var geocoder = new AMap.Geocoder({
//city: "010", //城市,默认:“全国”
radius: 1000 //范围,默认:500
});
//根据地址获得地理编码
geocoder.getLocation(orgAddress, function(status, result) {
if (status === 'complete' && result.info === 'OK') {
geocoder_CallBack(result);
}
});
});
//地理编码处理函数
function geocoder_CallBack(data) {
//地理编码结果数组
var geocode = data.geocodes;
for (var i = 0; i < geocode.length; i++) {
//一个地址可能会返回多个结果,地图上只显示最后一个
document.getElementById("adressId").innerHTML = geocode.formattedAddress;
document.getElementById("LngId").innerHTML = geocode.location.getLng();
document.getElementById("LatId").innerHTML = geocode.location.getLat();
//每个结果都画标记
addMarker(i, geocode);
}
};
function addMarker(i, d) {
map.setZoom(15);
map.setCenter([ d.location.getLng(), d.location.getLat()]);
var marker = new AMap.Marker({
map: map,
position: [ d.location.getLng(), d.location.getLat()]
});
};
//绑定鼠标点击事件
AMap.event.addListener(map,'click',getClickedLnglat);
//鼠标在地图上点击,获取经纬度坐标
function getClickedLnglat(e) {
//清楚原有标记,在鼠标点击的位置画上新标记
map.clearMap();
var marker = new AMap.Marker({
map: map,
position: [ e.lnglat.getLng(), e.lnglat.getLat()]
});
document.getElementById("LngId").innerHTML = e.lnglat.getLng();
document.getElementById("LatId").innerHTML = e.lnglat.getLat();
var position = {
"fLgn": e.lnglat.getLng(),
"fLat":e.lnglat.getLat()
};
//调用父窗口代码 将用户鼠标点击的位置返回
var partenW = window.parent;
var parentDiv = partenW.document.getElementById('ContextForId');
var parentModel = partenW.justep.Util.getModel(parentDiv);
parentModel.setPosition(position);
}
</script>
</body>
</html>
(完) |
|