[英]Get Coordinates/Geopoint for given CivicAddress on Windows Phone 8.1
從Evey那里,我發現了如何獲取一組特定坐標的CivicAddress
,就像這樣(感謝@Romasz作為答案):
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;
但是,我有CivicAddress
但我需要知道它的坐標。 我怎樣才能做到這一點?
MapLocationFinderResult具有一些有用的屬性,您應該能夠像這樣檢索GeoPoint :
Geopoint point = result.Locations.FirstOrDefault().Point;
這是針對您問題中的代碼的。 但是,如果要根據名稱來查找內容,則可以使用MapLocationFinder.FindLocationsAsync :
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("Hospital", myGeopoint, maxResults);
Geopoint point = result.Locations.FirstOrDefault().Point;
此方法中的GeoPoint用作幫助程序-區域中可能有很多“醫院”,並且該方法應返回最接近的“醫院”。
編輯-一些更多信息:
如果您不想提供任何起始GeoPoint ,請提供默認值:
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("Lizbona", new Geopoint(new BasicGeoposition()), 5);
var point = result.Locations.ToList();
記住結果取決於您在字符串中輸入的內容,對於上面的示例,我得到兩個結果-一個在葡萄牙的地理Lat = 38,72 Long = -9,15
,在波蘭的地理Lat = 52,67 Long = 16,48
(代表波蘭的城鎮)。 兩者都存在並且都是正確的-這僅取決於您的輸入。 另一方面,如果我搜索"Lizbon"
,則只有一個結果;如果"Lisbon"
,則只會得到四個結果。 這也可能取決於用戶的語言。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.