我知道我们已经有一些类似的问题但是所有这些问题都无法解决我的问题(因为差异平台)。所以我在这里提出我的问题,希望有人可以帮助我。
我正在开发一个xamarin项目并使用Google Map API ver 2制作地图。 当我触摸地图时,我将使用此代码添加新标记。
public void AddPoint(LatLng pointPossition)
{
MarkerOptions markerPoint = new MarkerOptions();
markerPoint.Anchor (0.5f, 1.0f);//The same issue occur when I remove this line
markerPoint.InvokeIcon(m_PointMoveableIcon);
markerPoint.SetPosition (pointPossition);
markerPoint.Draggable (true);
Marker marker = m_Map.AddMarker(markerPoint);//m_Map is the Google Map
m_Markers.Add(marker);//m_Markers is a list to store all created markers
}
通过这种方式,我可以在地图上创建一些制造商
所有标记都是可拖动的,因此我可以长按任何标记并将其拖动到另一个位置,但不幸的是,拖动标记突然改变位置,这种行为非常糟糕。
我尝试了很多解决方案但没有工作。所以,我希望有人可以帮助我。
提前感谢。
答案 0 :(得分:0)
我现在有这个任务。这是我的解决方案,下面的代码。 我不知道为什么是第一个数字,但是它适用于我的调试器。 0.5可能是标记位置的一半。
private void Map_PinDragging(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
private void Map_PinDragStart(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
Pin DragPin;
private void Map_PinDragEnd(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801*0.5), e.Pin.Position.Longitude);
}
然后... 这个值随着我的地图缩放而改变。那里需要一些数学。