如何在 Google Maps API 中调用行车路线后获取标记?
我昨天刚刚开始使用 Google Maps API,并尝试设置前往我的地图的行车路线。我的问题是:当我调用函数 load 时,
// [...]
gdir = new GDirections(map, directionsPanel);
// [...]
gdir.load("from: " + fromAddress + " to: " + toAddress);
它返回一个其标记不可拖动的地图。因此,我需要使它们可拖动以便重新计算方向,但我无法获取标记对象。
有人知道我该怎么做吗?
I just started working using Google Maps API yesterday, and trying to set up drive directions to my map. My problem is: when I call the function load,
// [...]
gdir = new GDirections(map, directionsPanel);
// [...]
gdir.load("from: " + fromAddress + " to: " + toAddress);
it returns a map whose markers are not draggable. So, I need to make them draggable in order to recalculate the directions, but I can't get the markers objects.
Someone knows how can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 GDirections 对象上为 addoverlay 事件添加一个处理程序:
当您的 onGDirectionsAddOverlay 处理程序被调用时,您可以迭代新的标记并将它们替换为可拖动的副本:
您可以在此处找到此示例( 来源)。
You need to add a handler on the GDirections object for the addoverlay event:
When your onGDirectionsAddOverlay handler is called you can iterate through the new markers and replace them with draggable copies:
You can find a working example of this here (source).