I have added a map to the application from the toolbox, but I'm trying to figure out how to add a marker to the map which would be triggered by the click event of a button. I know how to get the devices current location like shown below.
But how would I add to this to draw a pin/marker on the map using this location data? Is there a simple method of adding the marker using the calculated lat/lng from this code snippet?
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
}
}
It's a bit more work than with 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);
User contributions licensed under CC BY-SA 3.0