我有一个ListView绑定到数据适配器后,我创建并加载我的位置对象与设备的geoloc(拉特/长)后,显示固定地标的距离。问题是,平均来说,下面的代码需要3-7秒才能加载,较长的过程是调用“requestLocationUpdates()”,如果没有NETWORK_SERVICE,并且GPS_SERVICE成为主要时,有时可能需要几分钟才能加载,使我的Activity ListView blank应该在Activity的OnCreate()上调用locationManager.requestLocationUpdates()?
OnCreate()Activity方法是requestLocationUpdates()被调用的最佳位置吗?
locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE); locationListener = new GeoLocationListener();
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setSpeedRequired(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
locationManager.requestLocationUpdates(provider,
0, //300000, // TODO: Default to Check Every 5 Minutes OR
0, //500, // TODO: Default to Check if device moves more than 500 meters
locationListener);
你说得对。我跑进这篇文章悬而未决的帮助:“你可能不关心所有可用的位置提供,但只是想提供最好的要做到这一点,我们指定例如,我们是否需要高度和方位,是否需要成本等等 我们现在可以向位置管理员询问最后一个已知位置,对于特定的提供商。这对于快速将您置于接近最后的位置,同时等待更新进入。“ http://marakana.com/forums/android/examples/42.html – CampbellGolf 2012-04-16 19:38:14