Snap to nearest street

前端 未结 2 1666
悲&欢浪女
悲&欢浪女 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:35

    Blackpool Community Church Javascript Team has an excellent example of exactly this (direct link to the fourth example). Check out their other examples as well.

    (disclaimer: I'm not affiliated with them, but have learned a lot about GMaps from their examples)

    Edit: I suspect the map events fire somewhat like this (pseudocode, for real event names etc. check the GMaps docs):

    • map click: mousedown, mouseup, click:{set red marker}
    • drag red marker: mousedown, dragstart{red marker}, mouseup, click:{set marker b} (mousedown+mouseup), dragend
    • both markers are set? Yes, get directions

    What I'd suggest: in red-marker and marker-A dragstart functions, set some flag "dragging a marker", reset it in dragend function; in the Set marker B function, only set marker if we're currently NOT dragging something (flag is not set).

提交回复
热议问题