1

I'm using DistanceWidget plugin. This is my code:

var distanceWidget = new DistanceWidget(map);
displayMarker(distanceWidget, markers);

google.maps.event.addListener(distanceWidget, 'distance_changed', function () {
   displayMarker(distanceWidget, markers);
});

google.maps.event.addListener(distanceWidget, 'position_changed', function () {
   displayMarker(distanceWidget, markers);
});

And this function show/hide marker

function displayMarker(circle, markers) {
    var bounds = circle.get('bounds');
    for (var i=0; i<markers.length; i++) {
        if(bounds.contains(markers[i].getPosition())) {
            markers[i].setVisible(true);
        } else {
            markers[i].setVisible(false);
        }
    }
}

This is my error Error

Hai Truong IT
  • 4,126
  • 13
  • 55
  • 102
  • The circle's bounds is a square. – geocodezip Jan 13 '16 at 13:56
  • related question: [Google maps JS API v3: get markers in circle with containsLocation() doesn't work - why?](http://stackoverflow.com/questions/28254090/google-maps-js-api-v3-get-markers-in-circle-with-containslocation-doesnt-wor) – geocodezip Jan 13 '16 at 14:25

1 Answers1

0

u need To check First weather a particular marker lies in circle or not if yes then it automatically appears in circle else u need to place that marker in that circle.

Other solution is: U need to use LatLngBounds method something like this

        var bounds = new google.maps.LatLngBounds();
        for (var i = 0, LtLgLen = arrZom.length; i < LtLgLen; i++) {
            bounds.extend(arrZom[i]);
        }
        map.fitBounds(bounds);

arrZom is a array which contains all marker's Lat and Lng (google.maps.LatLng)