geocoding and reverse geocoding

Post on 27-Jan-2017

400 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

05/01/2023 Prepared by ENG SOON CHEAH

Geocoding &

Reverse GeocodingPrepared by

ENG SOON CHEAHMicrosoft MVP

05/01/2023 Prepared by ENG SOON CHEAH

Enable Location Services

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;

05/01/2023 Prepared by ENG SOON CHEAH

Results

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();

} }

05/01/2023 Prepared by ENG SOON CHEAH

Results

This Result include Geocoding (Coordinates) and Reverse Geocoding

top related