1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
| <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="__CSS__/main.css">
<style type="text/css">
.content{width:600px; height: 350px;margin: 10px auto;}
.content table{width: 100%}
.content table td{vertical-align: middle;}
#city,#address{height:21px;background: #FFF;border:1px solid #d7d7d7; line-height: 21px;}
#city{width:60px}
#address{width:130px}
#is_dynamic_label span{vertical-align:middle;margin: 3px 0px 3px 3px;}
#is_dynamic_label input{vertical-align:middle;margin: 3px 3px 3px 50px;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=021c8fdab28e1941b3649ff34d23cd05"></script>
<script type="text/javascript" src="__JS__/jquery.js"></script>
<title>Affichage de la carte</title>
</head>
<body>
<div class="content">
<table>
<tr>
<td width="130"><var id="lang_city"></var>Ville:<input id="city" type="text" /></td>
<td width="190"><var id="lang_address"></var>Adresse:<input id="address" type="text" value="" /></td>
<td><input onclick="javascript:doSearch()" class="formInput01" type="button" value="Ok"></a></td>
</tr>
<tr>
<td>Latitude:<a id="lat"></a></td>
<td>Longitude:<a id="lng"></a></td>
<td>Lieu actuelle:<a id="_address"></a></td>
</tr>
</table>
<input type="hidden" value="{$_GET['id']}" name="id" id="id">
<div style="width:100%;height:340px;margin:5px auto;border:1px solid gray" id="container"></div>
</div>
<script type="text/javascript">
var map = new BMap.Map("container"),marker,point,styleStr,
lat = document.getElementById('lat'),
lng = document.getElementById('lng'),
_address = document.getElementById('_address'),
id = document.getElementById('id');
var api = frameElement.api, W = api.opener,
_lat = W.document.getElementById('lat'),
_lng = W.document.getElementById('lng'),
p_address = W.document.getElementById('address');
map.enableScrollWheelZoom();
map.enableContinuousZoom();
function doSearch(){
if (!document.getElementById('city').value) {
alert('Vous n\'avez pas entré la ville!');
return;
}
var search = new BMap.LocalSearch(document.getElementById('city').value, {
onSearchComplete: function (results){
if (results && results.getNumPois()) {
var points = [];
for (var i=0; i<results.getCurrentNumPois(); i++) {
points.push(results.getPoi(i).point);
}
if (points.length > 1) {
map.setViewport(points);
} else {
map.centerAndZoom(points[0], 13);
}
point = map.getCenter();
} else {
alert(lang.errorMsg);
}
}
});
search.search(document.getElementById('address').value || document.getElementById('city').value);
}
function init(e){
var geolocation = new BMap.Geolocation();
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.setCurrentCity("Paris"); // capital de France
if(_lat.value && _lng.value){
lat.innerHTML = _lat.value;
lng.innerHTML = _lng.value;
//
var point = new BMap.Point(_lng.value,_lat.value);
map.centerAndZoom(point, 18);
var geoc = new BMap.Geocoder();
geoc.getLocation(point, function(rs){
var addComp = rs.addressComponents;
_address.innerHTML =(addComp.province+ addComp.city+ addComp.district + addComp.street + addComp.streetNumber);
});
var marker = new BMap.Marker(point);// 创建标注
map.addOverlay(marker); // 将标注添加到地图中
}else{
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
map.centerAndZoom(new BMap.Point(r.point.lng, r.point.lat), 18); // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.setCurrentCity(r.address.city);
}
else {
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.setCurrentCity("paris"); // capital de France
}
},{enableHighAccuracy: true});
}
var geoc = new BMap.Geocoder();
map.addEventListener("click", function(e){
map.clearOverlays();
var pt = e.point;
geoc.getLocation(pt, function(rs){
var point = new BMap.Point(rs.point.lng,rs.point.lat);
map.centerAndZoom(point, 18);
var marker = new BMap.Marker(point);// 创建标注
map.addOverlay(marker); // 将标注添加到地图中
lat.innerHTML = rs.point.lat;
lng.innerHTML = rs.point.lng;
_address.innerHTML = rs.address;
});
});
}
init();
document.getElementById('address').onkeydown = function (evt){
evt = evt || event;
if (evt.keyCode == 13) {
doSearch();
}
};
api.button({
id:'ok',
name:'Ok',
callback:function(){
if(!lat.innerHTML && !lng.innerHTML){
alert('Veuillez confirmer l\'adresse actuelle!');
return false;
}
W.document.getElementById('lat').value = lat.innerHTML;
W.document.getElementById('lng').value = lng.innerHTML;
}
});
</script>
</body>
</body>
</html> |
Partager