简体   繁体   English

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

[英]Movable Marker in Mapstraction using Google Maps v3

I am trying to place a marker that can be moved (movable marker) using Mapstraction Google Maps v3. 我正在尝试使用Mapstraction Google Maps v3放置一个可以移动的标记(可移动标记)。 But I cannot find the right settings. 但我找不到合适的设置。

I can place a static marker. 我可以放置一个静态标记。 But cannot find the configuration for a movable marker. 但是找不到可移动标记的配置。 Any one has any thoughts on this? 有没有人对此有任何想法?

Cheers, RD 干杯,RD

(I assume you are using version 3.9 of the API) (我假设您使用的是API的3.9版本)

Have you tried setting draggable to true in the constructor? 您是否尝试在构造函数中将draggable设置为true?

(Which takes): (需要):

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

You could also look a bit further into the mouse event classes, the marker class has a SetPosition method, and mouse event has a OnMouseOver event or something to that degree and a OnMouseClick event, or something like that. 您还可以进一步了解鼠标事件类,标记类具有SetPosition方法,鼠标事件具有OnMouseOver事件或某种程度的事件以及OnMouseClick事件或类似事件。

Now I have never worked with this API before and I dont do to much Javascript but il try to make some pseudo code. 现在我以前从未使用过这个API,而且我没有做很多Javascript但是我试着制作一些伪代码。

Option A: 选项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 );

I assume that this may make the object draggable. 我认为这可能使对象可拖动。

Option B: 选项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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM