draggable pushpin windows phone 7 bing maps control
Just wondering if there are any decent resources on how to program a draggable pushpin for a map in a windows phone 7 application. I've had a good look and can only find information about开发者_Python百科 how to do it for a browser application.
Ideally I want the user to be able to click on a pushpin and drag it to a location on the map however, at the minute the only way I can think of doing this is for the user to drag the map and the pushpin remains at the centre of the map.
I've not seen this done on a WP7 app yet - but here is a description for Silverlight 3 - http://pietschsoft.com/post/2010/05/30/Draggable-Pushpins-using-Bing-Maps-Silverlight-Control.aspx
When implementing this I'd guess that you'd want to be careful about where you actually drop the icon in relation to your finger - e.g. if you look at how the text caret is moved in a text block when you click/hold/drag, then you'll see that the caret position is offset above the finger so that you can always see it.
Yes you can. Here is a nice writeup how to implement this behavior.
Draggable PushPins
I was able to drag a Pushpin by adding an event handler for MouseMove and updating the Pushpin to the location of the mouse.
<my:Pushpin x:Name="pushpin" MouseLeftButtonDown="pushpin_MouseLeftButtonDown" MouseLeftButtonUp="pushpin_MouseLeftButtonUp" MouseMove="pushpin_MouseMove"/>
But the problem is the Map Control will also pan at the same time you are dragging the Pushpin. To solve that I had to add an event handler for mouse up and mouse down to the Pushpin and one for MapPan for the Map Control.
private void mapControl_MapPan( object sender, MapDragEventArgs e )
{
if( isDragging )
{
e.Handled = true;
}
}
private void pushpin_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
{
pushpin.CaptureMouse( );
isDragging = true;
}
private void pushpin_MouseLeftButtonUp( object sender, MouseButtonEventArgs e )
{
pushpin.ReleaseMouseCapture( );
isDragging = false;
}
private void pushpin_MouseMove( object sender, MouseEventArgs e )
{
pushpin.Location = mapControl.ViewportPointToLocation( e.GetPosition( mapControl) );
}
That will prevent the map from panning while the Pushpin is being dragged.
精彩评论