gpt4 book ai didi

google-glass - 如何可靠地获取 Glass 上的最后一个位置?

转载 作者:行者123 更新时间:2023-12-04 10:25:25 29 4
gpt4 key购买 nike

方法getLastLocation()来自 LocationManager通常返回 null 并且选择最佳提供者非常棘手。文档说:

Warning: Do not use the LocationManager.getBestProvider() method or the constants GPS_PROVIDER or NETWORK_PROVIDER to listen for location updates. Glass uses a dynamic set of providers and listening only to a single provider may cause your application to miss location updates.



如何获得最佳最后位置?

最佳答案

由于 Glass 使用一组动态提供者,您需要从所有提供者中获取位置并选择最准确的位置:

 public static Location getLastLocation(Context context) {
LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.NO_REQUIREMENT);
List<String> providers = manager.getProviders(criteria, true);
List<Location> locations = new ArrayList<Location>();
for (String provider : providers) {
Location location = manager.getLastKnownLocation(provider);
if (location != null && location.getAccuracy()!=0.0) {
locations.add(location);
}
}
Collections.sort(locations, new Comparator<Location>() {
@Override
public int compare(Location location, Location location2) {
return (int) (location.getAccuracy() - location2.getAccuracy());
}
});
if (locations.size() > 0) {
return locations.get(0);
}
return null;
}

关于google-glass - 如何可靠地获取 Glass 上的最后一个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21364663/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com