如何找出Android中缺少GPS坐标的原因?标的、原因、Android、GPS

由网友(你曾点亮过°)分享简介:我正在尝试使用 GPS 获取设备的位置信息,但由于某种原因,有时会丢失两个坐标之一.I am trying to get a device's location information using GPS, but for some reason one of the two coordinates is missi...

我正在尝试使用 GPS 获取设备的位置信息,但由于某种原因,有时会丢失两个坐标之一.

I am trying to get a device's location information using GPS, but for some reason one of the two coordinates is missing sometimes.

这是代码:

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Log.d("LOCATION1", "Longitude: " + longitude);
Log.d("LOCATION2", "Latitude: " + latitude);

有时我确实得到了两个坐标,但并非总是如此,这让我想到了某处的某种延迟.发生这种情况时,有没有办法找出为什么 GPS 坐标丢失?

Sometimes I do get both coordinates, but not always, which makes me think about some kind of delay somewhere. Is there a way to find out why a GPS coordinate is missing when this happens?

推荐答案

因为 GPS 并不总是开启.getLastKnownLocation 将返回一个位置如果它知道一个并且它不是太陈旧.由于没有其他人在使用 GPS,它不知道其中之一.如果您需要位置,请 requestLocationUpdates 或 requestSingleUpdate,这将打开 GPS 并获取新位置.

Because the GPS isn't always on. getLastKnownLocation will return a location if it knows one and if it isn't too stale. Since nothing else was using the GPS, it doesn't know one. If you need a location, either requestLocationUpdates or requestSingleUpdate, which will turn on the GPS and get a new location.

阅读全文

相关推荐

最新文章