I'm migrating a WP8 App to W8.1 and I have been reading that Geoposition API should not be used more for W8.1/WP8.1 or newer OS (I read it on MSDN). However I cannot find any example or idea how to get my current location with Geopoint API. This is my current code:
public async void GetSinglePositionAsync() {
Geolocator geolocator = null;
Geopoint geoposition = null;
try
{
geolocator = new Windows.Devices.Geolocation.Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
geoposition = await geolocator.GetGeopositionAsync();
double latitude = geoposition.Position.Latitude;
double longitude = geoposition.Position.Longitude;
int altitude = (int)geoposition.Position.Altitude;
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
lblGravity.Text = ex.ToString();
}
}
My biggest problem is when I initialize the geposition variable because it give me this bug: "Cannot implicity convert type 'Windows.Devices.Geolocation.Geoposition' to 'Windows.Devices.Geolocation.Geopoint'" and I don't know how to cast it or another method to initialize it.
Thank you very much for your valuable time and help. The answer provided could be implemented for the newest Windows too.
This code is possible translation.
public async void getposition() {
Geolocator geolocator = new Geolocator();
Geoposition geoposition = null;
geoposition = await geolocator.GetGeopositionAsync();
MyMap.Center = geoposition.Coordinate.Point;
// zoom level
MyMap.ZoomLevel = 15;
}