2012-06-02 340 views

回答

2

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

您是否尝试过在构造函数设置拖动为真?

(需要):

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); 
+0

谢谢你的回复@的浮动脑。但是你的解决方案直接使用GMaps。我不打算这么做。我想通过Mapstraction使用GMaps。 – Rohitesh

+0

Mapstraction不支持编辑,历史上是因为地图提供者之间没有一致的支持,从而击败了抽象的对象。如果您需要这些功能,则应直接使用Google API。 – dez

+0

@Rohitesh对不起,我只是点了一下在Google XD上出现的第一件事。 –

相关问题