如果我要标记的地点包含在当前地图区域中,我正在尝试在google地图中进行标记。请看一下我的解释。
我有lat和log数组,例如
var locations = [
{lat: -31.563910, lng: 147.154312},
{lat: -33.718234, lng: 150.363181},
{lat: -33.727111, lng: 150.371124},
{lat: -33.848588, lng: 151.209834}
]
当用户环顾地图时,如果他到达上面数组中包含lat和lng的地方,我想向该地方的制造商展示。
我不知道该怎么做。你能解释一下吗?
我正在使用Google Map JavaScript API。
答案 0 :(得分:0)
var locations = [
{lat: -31.563910, lng: 147.154312},
{lat: -33.718234, lng: 150.363181},
{lat: -33.727111, lng: 150.371124},
{lat: -33.848588, lng: 151.209834}
]
var map = new google.maps.Map(document.getElementById('map'), {})
var current_view_port = map.getBounds()
location.forEach(function(item){
if(current_view_port.contains(item)){ //returns true if in view-port
//create a marker here
}
})
https://developers.google.com/maps/documentation/javascript/reference/coordinates#LatLngBounds