I've started using maps in a Windows phone application and I have figured out how to get the current coordinates but I'm not sure how to draw it as a pushpin on the map.
This is what I have so far which calls a GetCoordinates method and navigates to the map on a button click.Does anyone know how I could pass the coordinates to the map and draw it as a pushpin?
private async Task GetCoordinates(string name = "My Car")
{
await Task.Run(async () =>
{
// Get the phone's current location.
Geolocator MyGeolocator = new Geolocator();
MyGeolocator.DesiredAccuracyInMeters = 5;
Geoposition MyGeoPosition = null;
try
{
MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
MessageBox.Show(ex.Message);
}
});
}
//sets location of parking space using the GetCoordinates method
//opens map
private async void setLocationBtn_Click(object sender, RoutedEventArgs e)
{
await this.GetCoordinates();
NavigationService.Navigate(new Uri("/Maps.xaml", UriKind.Relative));
}
And this is the map class which doesn't do anyting yet, Is there a way I could pass the geocoordinates from the previous class to the map and draw a pushpin? I was thinking of doing this in the OnNavigatedTo method somehow :
public partial class Maps : PhoneApplicationPage { Geolocator geolocator = null; bool tracking = false; ProgressIndicator pi; MapLayer PushpinMapLayer;
public Maps()
{
InitializeComponent();
pi = new ProgressIndicator();
pi.IsIndeterminate = true;
pi.IsVisible = false;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
}