[英]Get Coordinates/Geopoint for given CivicAddress on Windows Phone 8.1
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): 从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;
However, I have the CivicAddress
but I need to know it's coordinates. 但是,我有
CivicAddress
但我需要知道它的坐标。 How can I do this? 我怎样才能做到这一点?
MapLocationFinderResult has some useful properties and you should be able to retrive the GeoPoint like this: MapLocationFinderResult具有一些有用的属性,您应该能够像这样检索GeoPoint :
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 :
但是,如果要根据名称来查找内容,则可以使用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. 此方法中的GeoPoint用作帮助程序-区域中可能有很多“医院”,并且该方法应返回最接近的“医院”。
EDIT - some more information: 编辑-一些更多信息:
If you don't want to provide any starting GeoPoint , then provide the default one: 如果您不想提供任何起始GeoPoint ,请提供默认值:
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). 记住结果取决于您在字符串中输入的内容,对于上面的示例,我得到两个结果-一个在葡萄牙的地理
Lat = 38,72 Long = -9,15
,在波兰的地理Lat = 52,67 Long = 16,48
(代表波兰的城镇)。 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. 另一方面,如果我搜索
"Lizbon"
,则只有一个结果;如果"Lisbon"
,则只会得到四个结果。 It probably will also depend on the user's language. 这也可能取决于用户的语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.