2011-09-29 73 views
0

有没有人有任何洞察到如何在运行芒果的WP7客户端上的地图上实现可拖动图钉?我有一个图钉绑定到地图上的地理位置,我希望用户能够将其拖动到地图上并记录它的新位置。我已经看到了一些资源,但它们是针对非WP7 Bing Maps控件的。任何帮助,将不胜感激。WP7在地图上拖动图钉

谢谢!

回答

1

e.GetPosition(元)给出相对于元素的位置传递参数。另外,使用ViewportPointToLocation进行转换的点必须与地图的位置相关。所以,你必须做到以下几点:

Pushpin myPin = sender as Pushpin; 
    Point p = e.GetPosition(**Map**); 
    g = Map.ViewportPointToLocation(p); 
0

如果有人好奇,这是我想出了解决方案:

XAML:

<map:Map x:Name="Map" Height="400" HorizontalAlignment="Left" Margin="6,10,0,0" VerticalAlignment="Top" Width="444" ZoomLevel="19" > 
    <map:Map.Mode><map:AerialMode /></map:Map.Mode> 
    <map:Pushpin x:Name="Pin" Background="Green" IsHitTestVisible="True" IsEnabled="True"> 
     <toolkit:GestureService.GestureListener> 
       <toolkit:GestureListener DragDelta="Pushpin_OnDragDelta" DragStarted="Pushpin_OnDragStarted" DragCompleted="Pushpin_OnDragCompleted"> 
       </toolkit:GestureListener> 
     </toolkit:GestureService.GestureListener> 
    <map:Pushpin.RenderTransform> 
      <TranslateTransform></TranslateTransform> 
    </map:Pushpin.RenderTransform> 
    </map:Pushpin> 
</map:Map> 

的.cs:

private void Pushpin_OnDragDelta(object sender, DragDeltaGestureEventArgs e) 
{ 
    Pushpin myPin = sender as Pushpin; 
    TranslateTransform transform = myPin.RenderTransform as TranslateTransform; 
    transform.X += e.HorizontalChange; 
    transform.Y += e.VerticalChange;         
} 

private void Pushpin_OnDragStarted(object sender, DragStartedGestureEventArgs e) 
{ 
    Map.IsEnabled = false; // prevents the map from dragging w/ pushpin 
} 

private void Pushpin_OnDragCompleted(object sender, DragCompletedGestureEventArgs e) 
{ 
    Map.IsEnabled = true;   
} 

有没有人必须对如何任何想法提取图钉新位置的地理坐标?我想下面的代码在事件处理程序,并没有给出正确的坐标:

Pushpin myPin = sender as Pushpin; 
Point p = e.GetPosition(myPin); 
g = Map.ViewportPointToLocation(p); 

myPin.location给老坐标

1

我知道这是一个迟到的反应,但我工作的一个类似的项目,并使用类似的办法,所以我想我会分享。这是我的第一篇文章与我,但我的方法,我曾经是那么干净:

创建两个全局双变量来保存X,Y坐标的:

double mapLocX; 
double mapLocY; 

这些全球双打设置为点的位置图钉在你DragStarted事件:

Point point = myMap.LocationToViewportPoint(myPin.Location); 
mapLocX = point.X; 
mapLocY = point.Y; 

在你dragDelta情况下,更改这些变量为您将图钉:

mapLocX += e.HorizontalChange; 
mapLocY += e.VerticalChange; 

现在在DragCompleted上创建一个新的点,它接受我们渲染的全局变量,并将它们映射到地理坐标,这里是踢球者;从的ObservableCollection中删除我们的旧针(我的是位置),并在新的图钉在我们新增加的坐标:

Point point = new Point(mapLocX, mapLocY); 
GeoCoordinate geoCoord = new GeoCoordinate(); 
geoCoord = myMap.ViewportPointToLocation(point); 

Locations.Remove(myPin.Location); 
Locations.Add(geoCoord); 

希望这有助于

0

你想拥有你的UI元素不是你的手指的起源对?试试这个:

Point pM = e.GetPosition(**Map**); 
Point pE = e.GetPosition(**UIElement**); 

Point origin = new Point(pM.X - pE.X, pM.Y - pE.Y); 
GeoCoordinate g = Map.ViewportPointToLocation(origin);