[英]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.