开发者

How can I draw marker on google maps in specified boundary?

I want to draw marker on google maps. The marker data is from JSON.(from json file, not from database) and all data have a geometry (latitude, longitude)

An important thing is when I drag google maps, the browser will show some boundary.

And then the markers have to show on only shown maps.

After drag map again, the marker resets and show new marker in new boundary.

goog开发者_运维问答le.maps.event.addListener(map, 'dragend', function(event) {
  var bd = map.getBounds();
  var ne = bd.getNorthEast();
  var sw = bd.getSouthWest();
  var nw = new google.maps.LatLng(ne.lat(), sw.lng());
  var se = new google.maps.LatLng(sw.lat(), ne.lng());

I can not progress any more..

Please give some example url or help..


So you've got the points for the 4 corners of some kind of boundary, and you want to put a marker in there. So you have a bunch of markers, but you only want to plot the ones that fall within the current bounds.

So something like this might work:

var latlng = new google.maps.LatLng(54.42838,-2.9623);
var marker = new google.maps.Marker({
    position: latlng, 
});

if (bd.contains(latlng)) {
    marker.setMap(map);
}

You might want to setMap(null) for any markers that fall outwith the bounds.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜