我很难弄清楚如何正确地获得Xamarin中两个Location
之间的距离。万能的Google表示,至少我一直都得到错误的结果。
此代码说明了问题。
public void OnLocationChanged(Location location)
{
// Longitude/Latitude of Tower Bridge.
location.Longitude = 51.5053446;
location.Latitude = -0.0765396;
foreach (var store in this.stores)
{
if (store.DistanceView != null)
{
Location store_loc = new Location(location.Provider);
//store_loc.Longitude = double.Parse(store.GPSN);
//store_loc.Latitude = double.Parse(store.GPSW);
// Longitude/Latitude of Big Ben.
store_loc.Longitude = 51.5005747;
store_loc.Latitude = -0.1247025;
var distance = location.DistanceTo(store_loc);
// Google Maps ("measure distance") says 3.44km.
// Xamarin (variable "distance") says 5351.983 meters.
store.DistanceView.Text = distance.ToString();
}
}
}
我正在使用的实际位置有所不同(出于隐私目的),但是测量误差相似,因为我得到的结果不是Google Maps测量的两倍,而是附近。无论如何,以上测量值应该匹配,但是不匹配。