抓到最近的街道 [英] Snap to nearest street

查看:94
本文介绍了抓到最近的街道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您最近一直在帮助我解决Google Map的一些问题,并且非常感谢您。



我几乎完成了这个任务 - 只有一个问题留下。当我将第一个标记放在地图上时,它会对齐最近的街道(这很好!),但是当我将第一个标记拖到另一个地方时,方向突然混乱了。你可以在 > http://dev.korebogen.dk/gmap/



我需要移动第一个标记(仍然贴紧),当我放置第二个标记,方向首先加载。但为了让第一个标记再次捕捉,我必须加载方向。



我希望你们中的一些人有解决方案。提前致谢。

解决方案

布莱克浦社区教会Javascript团队有一个完美的例子直接链接到第四个例子)。查看他们的其他例子。



(免责声明:我不附属于他们,但从他们的例子中学到了很多关于GMaps的知识)

b
$ b

编辑:
我怀疑地图事件是这样引发的(伪代码,真实事件名称等,请检查GMaps文档):


  • 地图点击:mousedown,mouseup,点击:{设置红色标记}

  • 拖动红色标记:mousedown,dragstart {red marker},mouseup ,点击:{set marker b} (mousedown + mouseup),dragend

  • 两个标记都已设置?是的,获取路线



我会建议:在red-marker和marker-A dragstart函数中,设置一些标志draging a标记,将其重置为dragend函数;在设置标记B函数中,如果我们当前不拖动某些东西(标记未设置),则只设置标记。


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.

解决方案

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).

这篇关于抓到最近的街道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆