我已经从工具箱中向应用程序添加了一个地图,但我正在尝试弄清楚如何在地图上添加一个标记,该标记将由按钮的单击事件触发。我知道如何获取设备的当前位置,如下所示。
但是我如何使用此位置数据添加到地图上绘制图钉/标记呢?是否有一种使用此代码段中的计算lat / lng添加标记的简单方法?
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00");
LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
StatusTextBlock.Text = "location is disabled in phone settings.";
}
//else
{
// something else happened acquring the location
}
}
答案 0 :(得分:2)
这比使用Windows 8要多得多:
var overlay = new MapOverlay { PositionOrigin = new Point(0.5, 0.5), GeoCoordinate = coordinate };
var img = new Image { Width = 56, Height = 56 };
img.Source = new BitmapImage { UriSource = new Uri("/Assets/Icons/pin.png", UriKind.Relative) };
img.Tag = coordinate;
img.Tap += delegate
{
// handle tap
};
overlay.Content = img;
var mapLayer = new MapLayer { overlay };
map.Layers.Add(mapLayer);