gpt4 book ai didi

javascript - 过滤谷歌地图范围内的标记

转载 作者:行者123 更新时间:2023-12-03 06:44:30 25 4
gpt4 key购买 nike

google.maps.event.addListener(map, 'idle', function (event) 
{
var ne = map.getBounds().getNorthEast();
//northeast lat and long

var sw = map.getBounds().getSouthWest();
//southwest lat and long

var x = document.getElementById('hdnControl').value;
// x contains all the markers retrived from database


// code part to filter markers withing bounds

}

var x 包含所有标记,我想放置边界内的标记。如何过滤边界内的标记?任何帮助将不胜感激

  x contains value as
[
{"Latitude":19.2094000000,"Longitude":73.0939000000},
{"Latitude":19.2244070000,"Longitude":73.1545760000},
{"Latitude":19.1659242536,"Longitude":82.2436523438},
{"Latitude":18.3336694458,"Longitude":80.4309082031}
]

//as it has been serialized with
//dt is datatable retrived from database
JavaScriptSerializer oSerializer = new JavaScriptSerializer();

var Result = (from c in dt.AsEnumerable()
select new
{
Latitude = c.Field<Decimal>("Latitude"),
Longitude = c.Field<Decimal>("Longitude")
}).ToList();

hdnControl.Value = oSerializer.Serialize(Result);

最佳答案

LatLngBounds对象带有一个 contains() 方法,该方法接受一个 LatLng 点,如果该点恰好在边界内,则返回 true,如果在边界外,则返回 false。

下面是一个示例代码,用于指示标记是否在边界内:

function check_is_in_or_out(marker){
return map.getBounds().contains(marker.getPosition());
}

这里有一个相关的 SO 票证,讨论如何使用 bounds.contains():check if map markers are within selected bounds

关于javascript - 过滤谷歌地图范围内的标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37806015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com