geocoding and reverse geocoding

7
Geocoding & Reverse Geocoding Prepared by ENG SOON CHEAH Microsoft MVP 06/21/2022 Prepared by ENG SOON CHEAH

Upload: cheah-eng-soon

Post on 27-Jan-2017

400 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Geocoding &

Reverse GeocodingPrepared by

ENG SOON CHEAHMicrosoft MVP

Page 2: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Enable Location Services

Page 3: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Get the Coordinates Geolocator geolocator = new Geolocator();

// Define the accuracy for the location service in meters // There is no point to set the accuracy to any value below 5; // Also can define the location service accuracy in DesiredAccuracy with the options of Default or High geolocator.DesiredAccuracyInMeters = 10;

Geoposition currentposition = await geolocator.GetGeopositionAsync( maximumAge: TimeSpan.FromMinutes(5), // to specify the aging of the cache timeout: TimeSpan.FromSeconds(10)); // to specify the timeout for the getting the location information

// There is meaningless to obtaion the position value beyond 6 decimal points. // It will ONLY crate unncessary calculation. // // Obtain the position value from Coordinate.Point.Position, the information in .Coordinate is retiring. string latitude = currentposition.Coordinate.Point.Position.Latitude.ToString("0.000000"); string longitude = currentposition.Coordinate.Point.Position.Longitude.ToString("0.000000");

txtLocation.Text = latitude + "," + longitude;

Page 4: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Results

Page 5: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Reverse Geocodingvar geolocator = new Geolocator();

geolocator.DesiredAccuracyInMeters = 100; geolocator.DesiredAccuracy = PositionAccuracy.High; Geoposition position = await geolocator.GetGeopositionAsync();

// reverse geocoding BasicGeoposition myLocation = new BasicGeoposition { Longitude = position.Coordinate.Point.Position.Longitude, Latitude = position.Coordinate.Point.Position.Latitude

}; Geopoint pointToReverseGeocode = new Geopoint(myLocation);

MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

if (result.Status == MapLocationFinderStatus.Success) { if (result.Locations.Count != 0) { // here also it should be checked if there result isn't null and what to do in such a case string country = result.Locations[0].Address.FormattedAddress; txtLocation.Text += country.ToString();

} }

Page 6: Geocoding  and Reverse Geocoding

05/01/2023 Prepared by ENG SOON CHEAH

Results

This Result include Geocoding (Coordinates) and Reverse Geocoding