From eveywhere I've looked I found how to get the CivicAddress
of a specific set of coordinates, like so (thanks @Romasz for the answer):
var geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 100;
Geoposition position = await geolocator.GetGeopositionAsync();
// reverse geocoding
BasicGeoposition myLocation = new BasicGeoposition {
Longitude = position.Coordinate.Longitude,
Latitude = position.Coordinate.Latitude
};
Geopoint pointToReverseGeocode = new Geopoint(myLocation);
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);
string country = result.Locations[0].Address.Country;
However, I have the CivicAddress
but I need to know it's coordinates. How can I do this?
MapLocationFinderResult has some useful properties and you should be able to retrive the GeoPoint like this:
Geopoint point = result.Locations.FirstOrDefault().Point;
That's for the code from your question. However if you want to find something depending on its name, then you can use MapLocationFinder.FindLocationsAsync :
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("Hospital", myGeopoint, maxResults);
Geopoint point = result.Locations.FirstOrDefault().Point;
GeoPoint in this method is used as a helper - there may be many 'Hospitals' in area and the method should return the nearest one.
EDIT - some more information:
If you don't want to provide any starting GeoPoint , then provide the default one:
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("Lizbona", new Geopoint(new BasicGeoposition()), 5);
var point = result.Locations.ToList();
Remember the results depend on what you put in the string, for the above example I get two results - one in Portugal with geoposition Lat = 38,72 Long = -9,15
and second in Poland with geoposition Lat = 52,67 Long = 16,48
(which statnds for town in Poland). Both exist and both are correct - it just depends on your input. On the other hand if I search for "Lizbon"
- I will get only one result, if "Lisbon"
- four results. It probably will also depend on the user's language.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.