- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Google Maps JavaScript API V2 标记保存在数组中的位置。具有不同坐标的标记显示得很好,但我不知道如何显示具有相同坐标的各种标记。我需要它,因为一组位置可以具有相同的坐标,但具有不同的描述。如何显示这些不同的描述?
添加标记的代码是:
var map;
function loadEarth(mapdiv) {
if (GBrowserIsCompatible()) {
if(!mapdiv)
return true;
map=new GMap2(document.getElementById("map"));
map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
map.addControl(new GMapTypeControl());
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(40.186718, -8.415994),13);
}
}
function createMarker(point, number, description) {
var marker = new GMarker(point);
marker.value = number;
GEvent.addListener(marker, "click", function() {
var myHtml = "<b>#" + number + "</b><br/>" + description;
map.openInfoWindowHtml(point, myHtml);
});
return marker;
}
...
for(var i=0; i<gl_list.length; i++){
var point = new GLatLng(gl_list[i].Latitude,gl_list[i].Longitude);
description = "Visited place : "+gl_list[i].nome+" on : "+gl_list[i].data;
map.addOverlay(createMarker(point, i + 1, description));
}
感谢您的关注。
最佳答案
我经常在我的 map 上遇到完全相同的问题,并且发现自己担心相同的多个标记问题:哪个标记在顶部?用户如何看到它们?等等
最终,我认为问题实际上与标记无关;它实际上是关于 map 上的特定点。从用户的 Angular 来看,他们可能不太关心标记或标记周围的任何机制。他们真正关心的是与那个位置相关的信息。从这个 Angular 来看,挑战在于找到一种方法来为用户提供一种以直接方式查看相关信息的方法。所以我决定将占据相同位置的所有标记合并为一个标记,其中包含对用户重要的所有信息。
一步一步,这是我用来解决同一位置问题的多个标记的方法:
第 1 步: 对标记数据进行排序,以便识别占据相同位置的标记:
gl_list.sort( function( a, b ) {
var aLat = a.Latitude, bLat = b.Latitude;
if ( aLat !== bLat ) { return aLat - bLat; }
else { return a.Longitude - b.Longitude; }
});
第 2 步: 添加一个新函数,为 gl_list
数组的并置成员创建一个“特殊”标记:
var specialMarkers = null;
function createSpecialMarker( specialMarkers ) {
var infoWinContent = "<table class='special-infowin-table'>";
for ( var i = 0; i < specialMarkers.length; i++ ) {
infoWinContent +=
"<tr>" +
"<td class='special-table-label'>" +
"Visited Place [" + (i+1) + "]" +
"</td>" +
"<td class='special-table-cell'>" +
specialMarkers[i].nome + " on : " + specialMarkers[i].data +
"</td></tr>";
}
infoWinContent += "</table>";
var mrkrData = specialMarkers[0];
var point = new GLatLng( mrkrData.Latitude, mrkrData.Longitude );
var marker = new GMarker( point );
GEvent.addListener(marker, "click", function() {
map.openInfoWindowHtml( point, infoWinContent );
});
return marker;
}
第 3 步: 迭代标记数据,识别具有相同位置的分组,使用特殊标记在 map 上显示它们,并处理所有标记其他位置的数据“正常”:
for ( var i = 0; i < gl_list.length; i++ ) {
var current = gl_list[i];
var coLocated = null;
var j = 0, matchWasFound = false;
if ( i < ( gl_list.length - 1 ) ) {
do {
var next = assetData[ i + ++j ];
if ( next !== undefined ) { //just to be safe
if ( next.Latitude === current.Latitude &&
next.Longitude === current.Longitude ) {
matchWasFound = true;
if ( coLocated === null ) {
coLocated = new Array( current, next);
}
else { coLocated.push( next ); }
}
else { matchWasFound = false; }
}
else { matchWasFound = false; }
}
while ( matchWasFound )
if ( coLocated != null ) {
var coLoMarker = createSpecialMarker( coLocated );
if ( specialMarkers === null ) {
specialMarkers = new Array( coLoMarker );
}
else {
specialMarkers.push( coLoMarker );
}
i += --j;
continue;
}
var point = new GLatLng(gl_list[i].Latitude,gl_list[i].Longitude);
description = "Visited place : "+gl_list[i].nome +
" on : " + gl_list[i].data;
map.addOverlay( createMarker( point, i + 1, description ) );
}
}
想法是生成一个标记,让 InfoWindow 传达有关位置的多个重要信息,最终得到如下所示的内容:
现在我还没有运行这个实际代码,但它是基于每天运行的代码。这更多是为了让您更详细地了解该方法并分享一段代码,这些代码应该让您非常接近可用的解决方案,但要了解它可能需要一些调整和调试。
关于javascript - 谷歌地图 v2 : how to display various markers with the same coordinates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10508398/
我有一个名为 AnimalMarker 的类,它应该代表普通谷歌地图标记(纬度、经度、位置)和动物对象的最低限度。我正在使用 Firebase 实时数据库来存储这些 AnimalMarkers。 我想
我正在尝试创建一个准确的标记跟踪设备。我找到了 charuco 记号笔和钻石记号笔。 我能够通过charuco得到一个很好的校准结果。 现在,我必须将 3d 模型放在正确的位置。在我学习的过程中,我可
我有一张 map ,上面有根据数据库中的值以编程方式放置的标记。当您单击标记时,它将转到该位置的详细信息页面。 我的问题是,本地图充分缩小时,彼此足够接近的标记会显示为单个标记,实际上隐藏了一些标记。
所以我有一个带有很多标记的 MapView,其中大部分都集中在一英里宽的集群中。缩放时,标记重叠并且看起来只有一个。我想要实现的是在某个缩放级别将重叠标记替换为将显示标记密度的组标记,并且 onCli
我的编程非常基础,并且只需要针对一个特定项目的该选项。我很想通过单击不同的标记来更改一个主弹出窗口的内容。问题是,我不知道如何使用 .on('dblclick') 我的标记来获取不同标记上弹出窗口的
目前正在将一个使用 Google map 的 Android 应用程序迁移到 Google Maps Android v2;我希望 map 显示内置位置标记以及自定义标记。在以前的库中,我曾经在自定义
我喜欢使用 Google map 创建可以处理大量标记(超过 10,000 个)的 map 。为了不减慢 map 速度,我创建了一个 XML 文件,它只输出当前视口(viewport)内的标记。 首先
我有要在 map 中呈现的标记列表,但我想要一个一个地显示。第一次点击我想制作新的标记。然后当我点击另一个位置时,我希望我的标记只移动到新的 latLng 而不是创建另一个标记。这是我的代码: fun
有时在 Eclipse 中使用“Source > Sort Members”时,我会收到此警告消息。我假设“标记”指的是 these ,但是是什么造就了它们? 我不会手动制作它们。插件、FindBug
我有一张带有几种不同类型图标的 Google map 。我在每个图标上都有一个阴影。如何调整标记阴影与标记的偏移量? 在构建每个标记的循环中,我有: var icon = customIcons[ty
我发现下面的函数只创建一个标记 - 这正是我想要的。但是如何更改标记选项,例如html - 不创建一个新的? 即下面的代码将使用 setPosition 移动现有标记,但如果我还想更改其 html 和
当我使用 marker.setMap(null) 删除标记时,它一直可见,直到我缩小,此时 Google map 将其删除。 在与 Windows 上的 Chrome 相同的 HTML 页面上删除后,
我有一个弹出表单,当单击传单 map 中的某些标记时会出现该表单。表单完成后,我想将输入的字段以及有关标记的一些详细信息发送到单独的函数。我现在开始只是发送标记来测试它,但遇到了问题。 但是当我通过函
更新:我已经通过添加一个 previousMarker 对象解决了性能问题。因此只有之前点击的标记会被删除并替换为默认图标。然而,当我点击标记时,信息窗口仍然没有显示。 我有一个 map View 并
我正在使用 videojs-marker 插件 ( http://www.sampingchuang.com/videojs-markers ) 来构建一个自定义播放器,用户可以通过它来注释(命名一个
我想知道,免费版本...我可以绘制更多默认标记(来自 maps.google.com)。点击后会提供输入行车路线和其他从谷歌搜索的商家信息(例如:评论)的选项。 最佳答案 可以通过向信息窗口添加链接来
我想清除 Google map 上的标记。 marker.setVisible(false) 和有什么区别和 marker.setMap(null) ? 但我不知道,哪个是正确的? 最佳答案 这两种方
我正在使用 react-native-maps 但是我遇到了一个问题,在谷歌搜索了很多没有答案之后我不得不在这里问。我正在尝试使用自定义标记作为 map 中的标记,如下图所示 我在搜索中发现需要使用C
我在我的 Rails 应用程序中使用 Gmaps4Rails 加载谷歌地图。一切正常。我有一个标记,我想在加载谷歌地图时默认打开信息窗口(不点击标记)。请帮助我如何使用 Gmaps4Rails gem
我需要使用 Jackson 反序列化一个 json 对象. 经过多次努力和上网搜索,一切努力解决错误: Exception in thread "main" com.fasterxml.jackson
我是一名优秀的程序员,十分优秀!