- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试做一些与 Chris Essig 所做的非常相似的事情 here 。因为我需要知道在用户放下“trashMarker”的地方 20 米半径内有多少个数据点。
到目前为止我已经得到了这段代码:
// Create the FeatureGroup and add it to the map
var jsonGroup = new L.FeatureGroup();
mapOverview.addLayer(jsonGroup)
//Retrieve all data and add to map
$.each(datalistObject['idlist'], function(key, value) {
$.getJSON('http://mydata.com' + value['id'], function(data) {
textbox = value['name'];
var dataid = L.geoJson([data], {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: value['icon']
});
}
}).addTo(jsonGroup);
},function(xhr) { console.error(xhr); });
});
//Code to find the markers within a 20 meter radius of trashMarker
function markersInRadius() {
// Lat, long of trash marker on overview map
var trashMarkerLat_long = trashMarkerOverview.getLatLng();
// counter of the amount of markers that are within a 20 meter radius
var counter_markers_in_radius = 0;
console.log(jsonGroup);
// Loop through each point in JSON file
jsonGroup.eachLayer(function (layer) {
// Lat, long of current point
layerLatLong = layer.getLatLng();
// Distance from our circle marker
// To current point in meters
distance_from_layer_circle = layerLatLong.distanceTo(trashMarker_lat_long);
// See if meters is within raduis
// The user has selected
if (distance_from_layer_circle <= 20) {
counter_markers_in_radius += 1;
};
console.log(counter_markers_in_radius);
});
// Close pointsInCircle
};
当我运行此代码时,收到错误消息,指出 layer.getLatLng 不是函数。
在 jsonGroup 功能组上执行 console.log 后,我发现该组的图层选项卡中有两个对象,没有任何经纬度信息,而是有一个自己的图层选项卡,其中包含所有数据点latlng 信息...也许这就是问题所在?
最佳答案
通过在 jsonGroup 变量上运行 everyLayer 函数两次来修复它,如下所示:
function markersInRadius() {
// Lat, long of trash marker on overview map
var trashMarkerLatLng = trashMarkerOverview.getLatLng();
// counter of the amount of markers that are within a 20 meter radius
var pointsInRadius = 0;
console.log(jsonGroup);
// Loop through each point in JSON file
jsonGroup.eachLayer(function (layer) {
layer.eachLayer(function (layer) {
// Lat, long of current point
layerLatLong = layer.getLatLng();
// Distance from trashMarker
// To current point in meters
distanceFromTrashMarker = layerLatLong.distanceTo(trashMarkerLatLng);
// See if meters is within radius
if (distanceFromTrashMarker <= 20) {
pointsInRadius += 1;
};
});
});
console.log(pointsInRadius);
// Close pointsInCircle
};
关于javascript - 传单:layer.getLatLng 不适用于 .eachLayer 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31101736/
如何将 googleplacepicker 的 place.getLatLng() 函数给出的坐标拆分为单独存储的纬度和经度的双值。 place.getLatLng() 的输出示例为“lat/lng:
我正在尝试将该功能集成到 map 中,您可以在其中输入地址并在 map 上放置一个标记。但是对于 Google Maps getLatLng,如果地址名称中存在轻微错误,它就不再起作用了,您是说函数吗
我正在尝试使用下面的层循环 latlngs,在控制台中我只得到输出“0” for (var i in layer.getLatLngs()){ console.log(i);
我正在处理地点,我需要获取我所在位置的纬度和经度。这样我就成功搞定了 mLatLang = placeLikelihood.getPlace().getLatLng(); 其中 mLatLang 是
我正在尝试做一些与 Chris Essig 所做的非常相似的事情 here 。因为我需要知道在用户放下“trashMarker”的地方 20 米半径内有多少个数据点。 到目前为止我已经得到了这段代码:
大家好!我正在尝试使用 getLatLng() 对邮政/邮政编码列表进行地理编码,并将生成的点存储在数据库中,以便稍后放置在 map 上。这是我到目前为止所得到的: $(".geocodethis"
从自动完成点击一个地方后,我一直在尝试获取 latlng,奇怪的是 places.getName()工作正常,但 place.getLatLng()返回空值。我应该怎么做才能解决这个问题我是谷歌地图和
我是一名优秀的程序员,十分优秀!