0

this is my code google maps markers with circle, so I want on click not to draw markers if theres circles crossing each other

  google.maps.event.addListener(map, 'click', function(event) {
     var marker3 = placeMarker(event.latLng);
       google.maps.event.addListener(marker3, 'click', function(event) {
       });
  });
  function placeMarker(location) {
      var marker3 = new google.maps.Marker({
          position: location,
          map: map,
          draggable:true,   
      });
      radius = new google.maps.Circle(circleRadius);
      radius.bindTo('center', marker3, 'position');
      return marker3;
  }
3
  • 2
    loop through the existing markers, measure the distance (using the geometry library) from where you are about to put a marker to each marker's location. If that distance is greater than circleRadius, place the marker. If not, do nothing.
    – lucas
    Commented Jan 12, 2016 at 7:55
  • 1
    More context would be helpful!
    – jkalden
    Commented Jan 12, 2016 at 7:59
  • Unclear. What is circleRadius? Where does it come from? Is it always the same radius for each marker? "if circles cross each others", do you need to compare 2 markers or 1 markers towards many? Depending on your answers to these, you would get different answers. Dr.Molle's answer seems like a good solution if there are many markers.
    – MrUpsidown
    Commented Jan 12, 2016 at 12:44

1 Answer 1

1

Possible approach: Create 2 circles for each marker, the existing and another, transparent circle with double radius of the first marker.

The 2nd circle will not be visible on the map, but will still be there and prevent the map from triggering the click-event.

  radius = new google.maps.Circle(circleRadius);
  radius2 = new  google.maps.Circle({fillOpacity:.0001,
                                     strokeWeight:0,
                                     map:radius.getMap(),
                                     radius:radius.getRadius()*2});
  radius.bindTo('center', marker3, 'position');
  radius2.bindTo('center', marker3, 'position');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.