2012-06-02 338 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上出現的第一件事。 –

相關問題