如何从Xamarin Geolocation返回较短的坐标?

时间:2019-02-26 21:52:21

标签: xamarin geolocation

而不是像这样的坐标:纬度:99,9999397213696,经度:99,9999990115402 我想得到这样的东西:Lat 99.9999 lon 99.9999。

如何使地理位置更短/数值不太准确?

            var request = new GeolocationRequest(GeolocationAccuracy.Medium);
            var location = await Geolocation.GetLocationAsync(request);

1 个答案:

答案 0 :(得分:0)

如果要将数字显示为字符串,可以使用格式化程序:

var latString = $"Lat {location.Latitude:N4}";

N4string formatter的地方,有很多变化。

如果您实际上想舍入double值,则可以使用Math.Round

var rounded = Math.Round(location.Latitude, 4);

4是您想要的小数位数。