Google Map API更新实现用户自定义标注坐标

时间:2021-05-28

演示地址:http:///effects/img/icon13.png'
}),
draggable: true
};

marker = GoogleMap.createMarker(markPoint, markOptions);
GEvent.addListener(marker, "dragstart", function(){
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function(){
var custPoint = marker.getPoint();
var markTip = '<div class="fgmap_markerMsg" id="cusMarkTip">';
markTip += '<h4>用户地图标注</h4>';
markTip += '<div id="mapTips"><p>当前经纬度:(' + custPoint.lat() + ',' + custPoint.lng() + ')<br />';
markTip += '是否将新位置设置为此商户的默认位置?</p>';
markTip += '<div class="MDB" style="text-align:center;"><button id="MapOK" ';
marker.openInfoWindowHtml(markTip);
});
map.addOverlay(marker);
};

// 保存用户自定义坐标
GoogleMap.MapOk = function(){
var savedPoint = lastMarker.getPoint();
var lat = savedPoint.lat(), lng = savedPoint.lng();
var markTip = document.getElementById('cusMarkTip');
markTip.innerHTML = '<h4>正在上传您所保存的坐标信息...</h4>';
if (timer) {
clearTimeout(timer);
}
var timer = setTimeout(function(){
map.clearOverlays();
var marker = GoogleMap.createMarker(savedPoint);
if (GoogleMap.mapMsg) {
GEvent.addListener(marker, "click", function(){
var msg = '<span class="fgmap_markerMsg">', j;
msg += '<h4>' + GoogleMap.mapMsg[1][0] + '</h4>';
for (var j = 1; j < GoogleMap.mapMsg[1].length; j++) {
msg += GoogleMap.mapMsg[1][j] + "<br />";
}
msg += "</span>";
map.openInfoWindowHtml(savedPoint, msg);
});
}
map.addOverlay(marker);
map.setCenter(savedPoint);
cusLastPoint = [lat,lng];
}, 2000);
};

// 取消用户自定义坐标操作
GoogleMap.MapCancel = function(){
map.removeOverlay(lastMarker);
map.closeInfoWindow();
};

// 通过地址获得坐标
GoogleMap.getAddresslatlng = function(response){
var place = response.Placemark[0];
var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
return [place.Point.coordinates[1], place.Point.coordinates[0], point, place];
};

// 标注坐标和相应的说明信息
GoogleMap.MarkerMap = function(lat, lng){
var marker = null;
var point = new GLatLng(lat, lng);
GoogleMap.Map(lat, lng);

marker = this.createMarker(point);
if (GoogleMap.mapMsg) {
GEvent.addListener(marker, "click", function(){
var msg = '<span class="fgmap_markerMsg">', j;
msg += '<h4>' + GoogleMap.mapMsg[1][0] + '</h4>';
for (var j = 1; j < GoogleMap.mapMsg[1].length; j++) {
msg += GoogleMap.mapMsg[1][j] + "<br />";
}
msg += "</span>";
map.openInfoWindowHtml(point, msg);
});
}
map.addOverlay(marker);
};

// 将查询地址添加到地图
GoogleMap.addAddressToMap = function(response){
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("对不起, 我们解析不到该地址的经纬度坐标!");
}
else {
var marker = null, point = GoogleMap.getAddresslatlng(response);
var address = point[3].address, lat = point[0], lng = point[1];
GoogleMap.mapMsg = (GoogleMap.mapMsg !== '' && (lastAddress === GoogleMap.mapMsg[0])) ? GoogleMap.mapMsg : [address, [point[3].address, ('经度:' + point[1]), ('纬度:' + point[0])]];
GoogleMap.MarkerMap(lat, lng);
lastPoint = [lat,lng];
}
};

// 将查询坐标添加到地图
GoogleMap.addPointToMap = function(cPoint){
map.clearOverlays();
var marker = null, lat = cPoint[0], lng = cPoint[1];
GoogleMap.MarkerMap(lat, lng);
lastPoint = [lat,lng];
};

// 通过地址/坐标将Marker显示到地图上
GoogleMap.showLocation = function(cPoint){
if (typeof cPoint === 'string') {
geocoder.getLocations(cPoint, this.addAddressToMap);
lastAddress = cPoint;
}
else{
GoogleMap.addPointToMap(cPoint);
}
};

GEvent.addListener(window, 'unload', GUnload);
}
else {
alert("对不起,您的浏览器不支持创建地图!");
}
}
})();

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章