Google maps GoogleMap:我如何通过单击或在其周围绘制形状来选择我导入的多个标记,并将其保存为数据表?
我用Google map Maker创建了一张地图。为此,我导入了5个不同的Excel文件,其中包含地址字段,并将它们全部保存为不同的层。该地图现在有大约500个地址,这些地址用管脚标记,管脚按其所属的图层进行颜色编码。我没有代码,只有我创建的谷歌地图 我是否可以使用“绘制线”工具或其他方法来选择一组标记/引脚?理想情况下,我设想能够在它们周围绘制一个形状,然后能够选择这些地址,将它们保存为新的数据表或图层,以导出回Excel 有人知道实现这一目标的方法吗?即使它是另一种产品,谷歌地图?非常感谢你,任何帮助都能挽救生命。像这样的事情Google maps GoogleMap:我如何通过单击或在其周围绘制形状来选择我导入的多个标记,并将其保存为数据表?,google-maps,google-maps-api-3,gis,kml,Google Maps,Google Maps Api 3,Gis,Kml,我用Google map Maker创建了一张地图。为此,我导入了5个不同的Excel文件,其中包含地址字段,并将它们全部保存为不同的层。该地图现在有大约500个地址,这些地址用管脚标记,管脚按其所属的图层进行颜色编码。我没有代码,只有我创建的谷歌地图 我是否可以使用“绘制线”工具或其他方法来选择一组标记/引脚?理想情况下,我设想能够在它们周围绘制一个形状,然后能够选择这些地址,将它们保存为新的数据表或图层,以导出回Excel 有人知道实现这一目标的方法吗?即使它是另一种产品,谷歌地图?非常感谢
<head>
<style>
html, body, #map-canvas {
height: 400px;
margin: 0px;
padding: 0px
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<script>
var random_marker_locations = [
new google.maps.LatLng(50.7, 4.1),
new google.maps.LatLng(50.4, 4.2),
new google.maps.LatLng(50.1, 4.3),
new google.maps.LatLng(50.8, 4.4),
new google.maps.LatLng(50.5, 4.5),
new google.maps.LatLng(50.2, 4.6),
new google.maps.LatLng(50.9, 4.7),
new google.maps.LatLng(50.6, 4.8),
new google.maps.LatLng(50.3, 4.9)
]
var map;
var markers = [];
var polygon;
var polygonMarkers = [];
var polygonLocations = [];
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(50.40, 4.34), // Brussels, Belgium
mapTypeId: google.maps.MapTypeId.ROADMAP
};
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// add markers
for(var i in random_marker_locations) {
var marker = new google.maps.Marker({position: random_marker_locations[i], map: map, title: 'marker ' + i});
markers.push(marker);
}
// add a click on map event
google.maps.event.addListener(map, 'click', function(e) {
// set a marker there, with a small measle icon
var position = e.latLng;
polygonLocations.push(position);
polygonMarkers.push(new google.maps.Marker({
icon: 'https://maps.gstatic.com/intl/en_ALL/mapfiles/markers2/measle.png',
position: position,
map: map
}));
// now let's add a polygon
drawPolygon(polygonLocations);
});
}
// draws a polygon
function drawPolygon(points) {
if(points.length < 3) {
return;
}
// first delete the previous polygon
if(polygon) {
polygon.setMap(null);
}
// @see https://developers.google.com/maps/documentation/javascript/examples/polygon-simple
polygon = new google.maps.Polygon({
paths: points,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map
});
// display to input
displaySelectedMarkers(polygon);
}
// display the selected markers to input.
function displaySelectedMarkers(polygon) {
// empty the input
document.getElementById('selected_markers').value = '';
var a=0; // I use this to set a comma between the values, but no comma at the end
for(var i in random_marker_locations) {
// @see https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation
if (google.maps.geometry.poly.containsLocation(random_marker_locations[i], polygon)) {
document.getElementById('selected_markers').value += (a++>0 ? ', ' : '') + i ;
}
}
}
function clearSelection() {
if(polygon) {
polygon.setMap(null);
}
for (var i in polygonMarkers) {
polygonMarkers[i].setMap(null);
}
polygonLocations = [];
document.getElementById('selected_markers').value = '';
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<hr>
<input id="selected_markers"><br>
<input type="button" onclick="clearSelection()" value="Clear polygon"><br>
Click to select a polygon selection around the markers
</body>
html,正文,#地图画布{
高度:400px;
边际:0px;
填充:0px
}
变量随机标记位置=[
新的google.maps.LatLng(50.7,4.1),
新的google.maps.LatLng(50.4,4.2),
新的google.maps.LatLng(50.1,4.3),
新的google.maps.LatLng(50.8,4.4),
新的google.maps.LatLng(50.5,4.5),
新的google.maps.LatLng(50.2,4.6),
新的google.maps.LatLng(50.9,4.7),
新的google.maps.LatLng(50.6,4.8),
新google.maps.LatLng(50.3,4.9)
]
var映射;
var标记=[];
var多边形;
var polygonMarkers=[];
var polygonLocations=[];
变量映射选项={
缩放:8,
中心:新google.maps.LatLng(50.40,4.34),//比利时布鲁塞尔
mapTypeId:google.maps.mapTypeId.ROADMAP
};
函数初始化(){
map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
//添加标记
用于(随机标记位置中的var i){
var marker=new google.maps.marker({position:random_marker_locations[i],map:map,title:'marker'+i});
标记器。推(标记器);
}
//添加单击地图事件
google.maps.event.addListener(映射,'click',函数(e){
//在那里设置一个带有小measle图标的标记
var位置=e.latLng;
多点定位。推动(位置);
polygonMarkers.push(新的google.maps.Marker)({
图标:'https://maps.gstatic.com/intl/en_ALL/mapfiles/markers2/measle.png',
职位:职位,,
地图:地图
}));
//现在让我们添加一个多边形
drawPolygon(多边形定位);
});
}
//绘制多边形
函数绘制多边形(点){
如果(点长度<3){
返回;
}
//首先删除上一个多边形
if(多边形){
polygon.setMap(空);
}
//@见https://developers.google.com/maps/documentation/javascript/examples/polygon-simple
多边形=新的google.maps.polygon({
路径:点,
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:2,
填充颜色:'#FF0000',
不透明度:0.35,
地图:地图
});
//显示输入
显示选定的标记(多边形);
}
//显示要输入的选定标记。
函数显示SelectedMarkers(多边形){
//清空输入
document.getElementById('selected_markers')。值='';
var a=0;//我使用它在值之间设置一个逗号,但在末尾不设置逗号
用于(随机标记位置中的var i){
//@见https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation
if(google.maps.geometry.poly.containsLocation(随机标记位置[i],多边形)){
document.getElementById('selected_markers')。值+=(a++>0?',':'')+i;
}
}
}
函数{
if(多边形){
polygon.setMap(空);
}
for(polygonMarkers中的变量i){
polygonMarkers[i].setMap(null);
}
多基因定位=[];
document.getElementById('selected_markers')。值='';
}
google.maps.event.addDomListener(窗口“加载”,初始化);
单击以选择标记周围的多边形选择
Hi的可能副本的副本非常感谢您的回复!你是否可以给我指点一下指南的方向,或者解释一下我将如何“安装”这段代码?我不太熟悉谷歌地图,我想我没有意识到你可以“安装”你自己的代码到它。你可以复制粘贴我的代码到一个空的.htm文件,它会运行。因此,如果您可以将我的代码与html合并,它应该可以工作。确保您像我一样加载脚本文件。注意元素的id。让我知道它是否有效。非常感谢。所以我在这方面还是个新手。如何将代码粘贴到空的.htm文件并运行它?当我创建这张地图时,我访问了www.google.com/maps/d/并“创建了一张新地图”。然后我上传了KLM文件,我已经映射了所有带有标记的地址。这是我需要在谷歌地球上做的吗?很抱歉我希望不要打扰你,或者给你留下太多失败的印象。再次感谢。打开记事本,粘贴我发布的代码。将文件另存为index.htm。(如果您可以访问服务器)然后将该文件上载到服务器上的某个位置。在本地(比如如果你没有服务器的话),你只需用鼠标右键点击->打开Chrome(或者任何浏览器)哇。太棒了。非常感谢。所以现在我只需要复制地图的Html并将其与代码合并?你能告诉我怎么做吗?再次抱歉。希望不要成为麻烦。我确实看到了如何“查看源代码”来查看我的地图Html代码。