Johnston
Johnston

Reputation: 2883

Using Click event and Dragend event

I am wanting to have to event on my pins. one that when the user clicks on a pin a click method is called. A second method would be dragend for when the user drags the pin.

I currently have the following event handlers:

Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
Microsoft.Maps.Events.addHandler(pin, "dragend", endDragHandler);

the problem is that when the user only clicks on the pin, the endDragHandler gets called first and then calls the click method.

Any Suggestions on how to fix this?

Thanks

Upvotes: 1

Views: 1416

Answers (3)

Faisal Mq
Faisal Mq

Reputation: 5554

Although the question has already been answered, I found a solution at this CodeProject link, similar to what @johnston suggested above:

Basically on click event of pushpin, the new and old latitude/longitude is being compared in 3 decimal values. If it matches its assumed its a click event, otherwise its a drag event. I am though amazed as to why Bing team hasn't looked itself into this weird issue, that took me hours to sort out. Bing API should itself address this issue.

Upvotes: 0

Johnston
Johnston

Reputation: 2883

The solution I ended up comming up with was to check the current location and see if it was still in the same spot.

Upvotes: 1

Bojin Li
Bojin Li

Reputation: 5799

It certainly seems strange that dragend fires before click, but you are right this is indeed the case. The easiest workaround I can think of is this: rather than subscribing to the click event, suscribe to the mousedown event instead:

Microsoft.Maps.Events.addHandler(pin, 'mousedown', displayInfobox);
Microsoft.Maps.Events.addHandler(pin, "dragend", endDragHandler);

mousedown will fire before dragend. So if you can get away with using 'mousedown', I would suggest that you do this. If you must use click, things might get complicated.

Upvotes: 1

Related Questions