捕捉到最近的街道
你们最近一直在帮助我解决一些使用 Google 地图的问题,非常感谢你们。
我几乎已经完成了这个工作——只剩下一个问题了。 当我在地图上放置第一个标记时,它会捕捉到最近的街道(这很好!),但是当我将第一个标记拖到另一个地方时,方向突然变得混乱。 并且标记得到混合。
您可以在 http://dev.korebogen.dk/gmap/ 上看到一个示例,
我需要制作可以移动第一个标记(仍然捕捉),当我放置第二个标记时,方向首先加载。 但为了使第一个标记再次捕捉,我必须加载方向。
我希望你们中的一些人能找到解决方案。 提前致谢。
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. When I place the first marker on the map, it snaps to the nearest street (which is fine!) but when I drag the first marker to another place, directions suddenly mess up. And the markers get mixes.
You can see an example on http://dev.korebogen.dk/gmap/
I need to make it possible to move the first marker (still snapping) and when I place the second marker, the directions first load. But in order to make the first marker snap again, I have to load the directions.
I hope some of you have a solution. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Blackpool Community Church Javascript 团队有一个正是这方面的优秀示例 (直接链接到第四个示例)。 还可以查看他们的其他示例。
(免责声明:我不隶属于他们,但从他们的示例中学到了很多关于 GMap 的知识)
编辑:
我怀疑地图事件触发有点像这样(伪代码,真实事件名称等,请检查 GMaps 文档):
我的建议是:在红色标记和标记 A 拖动开始函数中,设置一些标志“拖动标记”,在拖动结束函数中重置它; 在设置标记 B 函数中,仅当我们当前未拖动某些内容(未设置标志)时才设置标记。
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):
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).
我之前给您的代码监听了前两次点击,并为每次点击添加了一个标记。 问题是,当您拖动第一个标记时,它会再次调用“单击”事件 - 从而在同一位置添加另一个标记。
幸运的是,点击事件可以让您知道单击了叠加。 因此,如果overlay为null,则仅执行添加新标记的代码。 请注意,overlay 不是布尔值。
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.