Snap to nearest street

前端 未结 2 1661
悲&欢浪女
悲&欢浪女 2020-12-17 04:12

You guys have been helping out solving some of my problems with a Google Map lately, and thank you for that.

I am almost done with this - only one problem is left. W

2条回答
  •  天涯浪人
    2020-12-17 04:36

    The code I gave you previously listened for the first two clicks, and added a marker for each. The problem is that when you drag the first marker, it's calling the "click" event again - and thus adding another marker at the same location.

    Fortunately, the click event lets you know whether an overlay was clicked. So only execute the code that adds a new marker if overlay is null. Note that overlay is not a boolean.

    var listener = GEvent.addListener(map, "click", function(overlay, latlng) {
      if (overlay == null) {
        // code to add new marker
      }
    });
    

提交回复
热议问题