...
|
...
|
@@ -22,52 +22,9 @@ |
|
|
min-height:767px;
|
|
|
}
|
|
|
</style>
|
|
|
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
|
|
|
<script>
|
|
|
var markersArray=[];
|
|
|
var init = function() {
|
|
|
var map = new qq.maps.Map(document.getElementById("container"),{
|
|
|
center: new qq.maps.LatLng(39.916527,116.397128),
|
|
|
zoom: 13,
|
|
|
});
|
|
|
//添加监听事件
|
|
|
qq.maps.event.addListener(map, 'click', function(data) {
|
|
|
|
|
|
for (i in markersArray) {
|
|
|
markersArray[i].setMap(null);
|
|
|
}
|
|
|
|
|
|
var anchor = new qq.maps.Point(6, 6),
|
|
|
size = new qq.maps.Size(24, 24),
|
|
|
origin = new qq.maps.Point(0, 0),
|
|
|
marker = new qq.maps.Marker({
|
|
|
map: map,
|
|
|
position:data.latLng});
|
|
|
markersArray.push(marker);
|
|
|
console.log(data);
|
|
|
document.getElementById('pointInput').value=data.latLng;
|
|
|
setTimeout(function(){
|
|
|
// alert(data.latLng);
|
|
|
},200);
|
|
|
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
function confirmSelect(){
|
|
|
var selectLocation = {};
|
|
|
var gpsAddr = document.getElementById('currentAddr');
|
|
|
var location = document.getElementById('pointInput');
|
|
|
/* selectLocation.gpsAddr = gpsAddr.innerHTML;*/
|
|
|
selectLocation.location = location.value;
|
|
|
console.log(selectLocation.location);
|
|
|
window.opener.SelectLocation.selectCallback(selectLocation);
|
|
|
window.close();
|
|
|
}
|
|
|
</script>
|
|
|
</head>
|
|
|
<body onload="init()">
|
|
|
<body onload="">
|
|
|
<div class="LogoCon clear" style="font-size:18px;">
|
|
|
|
|
|
<div style="display:block">
|
...
|
...
|
@@ -78,5 +35,136 @@ |
|
|
</div>
|
|
|
</div>
|
|
|
<div id="container"></div>
|
|
|
<!--<div id="searchPart">-->
|
|
|
<!--<input type="text" id="searchInput" placeholder="请输入">-->
|
|
|
<!--<button id="searchBtn">搜索</button>-->
|
|
|
<!--</div>-->
|
|
|
</body>
|
|
|
|
|
|
<script src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
|
|
|
<!--<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>-->
|
|
|
<script>
|
|
|
// var markersArray=[];
|
|
|
// var init = function() {
|
|
|
// var map = new qq.maps.Map(document.getElementById("container"),{
|
|
|
// center: new qq.maps.LatLng(39.916527,116.397128),
|
|
|
// zoom: 13,
|
|
|
// });
|
|
|
// //添加监听事件
|
|
|
// qq.maps.event.addListener(map, 'click', function(data) {
|
|
|
//
|
|
|
// for (i in markersArray) {
|
|
|
// markersArray[i].setMap(null);
|
|
|
// }
|
|
|
//
|
|
|
// var anchor = new qq.maps.Point(6, 6),
|
|
|
// size = new qq.maps.Size(24, 24),
|
|
|
// origin = new qq.maps.Point(0, 0),
|
|
|
// marker = new qq.maps.Marker({
|
|
|
// map: map,
|
|
|
// position:data.latLng});
|
|
|
// markersArray.push(marker);
|
|
|
// console.log(data);
|
|
|
// document.getElementById('pointInput').value=data.latLng;
|
|
|
// setTimeout(function(){
|
|
|
// // alert(data.latLng);
|
|
|
// },200);
|
|
|
//
|
|
|
//
|
|
|
// });
|
|
|
// }
|
|
|
|
|
|
var map, marker, infoWindow;
|
|
|
// 创建信息窗口
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var center = new TMap.LatLng(39.984104, 116.307503);//设置中心点坐标
|
|
|
//初始化地图
|
|
|
var map = new TMap.Map("container", {
|
|
|
center: center
|
|
|
});
|
|
|
|
|
|
//初始化marker图层
|
|
|
var markerLayer = new TMap.MultiMarker({
|
|
|
id: 'marker-layer',
|
|
|
map: map
|
|
|
});
|
|
|
|
|
|
//监听点击事件添加marker
|
|
|
map.on("click", (evt) => {
|
|
|
|
|
|
|
|
|
console.log(evt.latLng);
|
|
|
document.getElementById('pointInput').value=evt.latLng
|
|
|
|
|
|
});
|
|
|
|
|
|
function searchClick() {
|
|
|
let searchInput = document.getElementById('searchInput').value; // 获取搜索内容
|
|
|
let url = [
|
|
|
'https://apis.map.qq.com/ws/place/v1/search',
|
|
|
'?boundary=nearby(39.984104,116.307503,1000,0)',
|
|
|
`&keyword=${searchInput}`,
|
|
|
'&page_size=10&page_index=1&orderby=_distance',
|
|
|
'&output=jsonp&callback=cb',
|
|
|
'&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77'
|
|
|
].join('');
|
|
|
jsonp_request(url);
|
|
|
infoWindow.close(); // 关闭信息窗口
|
|
|
}
|
|
|
// 添加搜索按钮点击事件
|
|
|
const searchBtn = document.getElementById('searchBtn');
|
|
|
searchBtn.addEventListener('click', searchClick, false);
|
|
|
|
|
|
function jsonp_request(url) {
|
|
|
let script = document.createElement('script');
|
|
|
script.src = url;
|
|
|
document.body.appendChild(script);
|
|
|
}
|
|
|
|
|
|
function confirmSelect(){
|
|
|
var selectLocation = {};
|
|
|
var gpsAddr = document.getElementById('currentAddr');
|
|
|
var location = document.getElementById('pointInput');
|
|
|
/* selectLocation.gpsAddr = gpsAddr.innerHTML;*/
|
|
|
selectLocation.location = location.value;
|
|
|
console.log(selectLocation.location);
|
|
|
window.opener.SelectLocation.selectCallback(selectLocation);
|
|
|
window.close();
|
|
|
}
|
|
|
|
|
|
|
|
|
function cb(ret) {
|
|
|
let newBounds = new TMap.LatLngBounds();
|
|
|
let markerArr = [];
|
|
|
if(ret && ret.status===0 && ret.data.length>0) {
|
|
|
// 将搜索结果保存进数组中
|
|
|
ret.data.forEach( (item, index) => {
|
|
|
let position = new TMap.LatLng(item.location.lat, item.location.lng);
|
|
|
markerArr.push({
|
|
|
position: position,
|
|
|
properties: {
|
|
|
title: item.title,
|
|
|
address: item.address,
|
|
|
tel: item.tel!==' ' ? item.tel : '暂无'
|
|
|
}
|
|
|
});
|
|
|
// 寻找搜索结果的边界
|
|
|
newBounds.extend(position);
|
|
|
});
|
|
|
// 更新marker层,显示标记
|
|
|
marker.setGeometries(markerArr);
|
|
|
// 地图自适应边界
|
|
|
map.fitBounds(newBounds, {
|
|
|
padding: 100 // 边界与内容之间留的间距
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
</html> |
|
|
\ No newline at end of file |
...
|
...
|
|