开发者

Google Maps API v3: Does placemarker exist on given LatLng?

I want to find out using the API if a marker has been placed开发者_高级运维 on google maps at a given LatLng. Is this possible without me saving all the latlngs at which the placemarker is placed?


No. The API doesn't track your markers, so you will need to track them yourself. I suggest adding each location to an array, and then writing a function which can check whether any marker in that array is located at a specific lat/lng.

Something like:

var marker_locations = [];

function addMarker(latlng) {
   marker = new google.maps.Marker(....);
   marker.setMap(map);
   marker_locations.push(latlng);
}

function markerAtPoint(latlng) {
  for (var i = 0; i < marker_locations.length; ++i) {
    if (marker_locations[i].equals(latlng)) return true;
  }
  return false;
}


Try using map.getBounds().contains(marker.getPosition()) and replace getPosition() with your latlng. I haven't tested this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜