我有下面的代码检查地图标记是在地理围栏内部还是外部。
我将使其警报检测到超出范围。
我的问题是地图标记不断刷新,我不希望警报重复一遍。
闹钟响起时我需要设置一些东西。然后仅在该事物未设置时才发出警报。
当检测到用户回到边界内时,它也会取消设置。
if (name === f.contact) {
var fence = new google.maps.LatLng(f.lat, f.lng);
var dist = google.maps.geometry.spherical.computeDistanceBetween(posi, fence);
// check if in/out of fence
if (dist > f.radius) {
console.log(f.contact+" : "+dist+" meters - outside the fence");
// OMG outside the fence play an alarm
} else {
console.log(f.contact+" : "+dist+" meters - inside the fence");
// Back inside the fence, reset the alarm
}
}
我在想可能做一个这样的数组
var alertSent = [];
然后如果在地理围栏之外添加用户名
alertSent.push(name);
我将如何检查名称是否存在于数组中?
回到栅栏内时,我将如何从数组中删除名称?