本文介绍了禁止拖拽“来源” Google Maps v3 Directions API中的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Google Maps Directions API的v3显示地图。我无法弄清楚如何在目标上启用标记拖动功能,并禁用拖动原点标记。



我明白这可以在这里设置:


$ b $然而,如何访问正确的标记以禁用拖动?通过zIndex?我也试过

response.routes [0] .legs [0] .start_location
没有效果。任何指针?

解决方案

想象一下,Ya'll:



链接:



编辑(改为粗体):

//用于禁用拖动origen :)(第78行)

startLocation.marker = createMarker(legs [i] .start_location,start,legs [i] .start_address,green, false );

//用于启用拖动:(目的地)(第108行)

endLocation.marker = createMarker(endLocation.latlng,end ,endLocation.address,red, true );

//更新createMarker函数(第175行)

createMarker(latlng,lable,html,color, drag

//更新google.maps.Marker(第178行)

var marker = new google.maps.Marker({

position:l atlng,

可拖动:拖动

地图:地图,

阴影:iconShadow,

图标:getMarkerImage(color),

shape:iconShape,

title:label,

zIndex:Math.round(latlng.lat()* - 100000) << 5

});

* 注意:您还需要标记,找到和 - 并放置在一个名为mapIcons /的代码的相同目录中的文件夹*


I'm attempting to display a map using v3 of Google Maps Directions API. I can't figure out how to enable dragging on the marker for the "destination" and disable the dragging for the "origin" marker.

I understand this can be set here:http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerOptions

however, how to access the correct marker to disable dragging? by zIndex? I've also tried
response.routes[ 0 ].legs[ 0 ].start_location with no effect. Any pointers?

解决方案

Figured It Out, Ya'll:

Link: Customer Marker Example, with some minor changes show below:

Edit (change in bold):

// for disabled dragging (origen:) (line 78)
startLocation.marker = createMarker(legs[i].start_location,"start",legs[i].start_address,"green", false);

// for enabled dragging: (destination) (line 108)
endLocation.marker = createMarker(endLocation.latlng,"end",endLocation.address,"red", true);

// update createMarker function (line 175)
createMarker(latlng, lable, html, color, drag)

// update google.maps.Marker (line 178)
var marker = new google.maps.Marker({
position: latlng,
draggable: drag,
map: map,
shadow: iconShadow,
icon: getMarkerImage(color),
shape: iconShape,
title: label,
zIndex: Math.round(latlng.lat()*-100000)<<5
});

*Note: you will also need the markers, found here and here - and place in a folder in the same dir as code called "mapIcons/" *

这篇关于禁止拖拽“来源” Google Maps v3 Directions API中的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 01:49