0

我正在尝试使用 Mapstraction Google Maps v3 放置一个可以移动的标记(可移动标记)。但我找不到正确的设置。

我可以放置一个静态标记。但找不到可移动标记的配置。有人对此有任何想法吗?

干杯,RD

4

1 回答 1

2

(我假设您使用的是 3.9 版的 API)

您是否尝试在构造函数中将 draggable 设置为 true?

(需要):

https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions

您还可以进一步研究鼠标事件类,标记类具有 SetPosition 方法,鼠标事件具有 OnMouseOver 事件或某种程度的事件和 OnMouseClick 事件或类似事件。

现在我以前从未使用过这个 API,我没有做太多的 Javascript,但我尝试制作一些伪代码。

选项 A:

var default = new google.maps.MarkerOptions;
//Other setting's go here.//
default.draggable = true;
//For fun.//
default.raiseOnDrag = true;
//Example object.//
var marker = new google.maps.Marker( default );

我认为这可能会使对象可拖动。

选项 B:

/*This function will check if we are going to move our marker and then do it if
the conditions are right.*/
function CheckMoveMarker( var marker )
{
   //Make a new mouse event.//
   mouseStuff = new google.maps.SomePseudoMouseEvent();

   //In the real API this was an event but I dident want to write one... :-P//
   if( mouseStuff.isOver( marker.getRect() ) == true ) {

      //You may want to pop a thread here.//
      while ( mouseStuff.mouseClicked() == true ) {

         /*You may need some clever way to get the position, perhaps through
         the "map" class: https://developers.google.com/maps/documentation
         /javascript/reference#Map .*/

         marker.setPosition( mouseStuff.x, mouseStuff.y );
      }
   }

   //Return the changes to our marker.//
   return marker;
}


//Somewhere in your code.//
myMarker = CheckMoveMarker( myMarker );
于 2012-06-02T15:03:42.517 回答