使用Google Maps v3在Mapstraction中移动标记

时间:2012-06-02 14:22:12

标签: google-maps-api-3 google-maps-markers mapstraction

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

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

干杯, RD

1 个答案:

答案 0 :(得分:2)

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

您是否尝试在构造函数中将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 );