我有这段代码:
if (item.getItemId() == R.id.tempMap) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = null;
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)||locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 20000, 1, this);
if (location != null) {
Log.e("PROVIDER SCELTO", provider);
onLocationChanged(location);
Log.e("LATITUDE", String.valueOf(latitude));
Log.e("LONGITUDE", String.valueOf(longitude));
和
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
}
但是它返回的最后一个gps点是我使用“google maps navigator”后的最后一点。因此,如果我不使用gm导航器,则不会更新纬度和经度。
WHY ???
谢谢
答案 0 :(得分:0)
位置修复需要时间等待,直到获得良好的修复,这将检查修复的时间并仅在修复时间段内设置位置,如果您不检查修复的时间,它将提供最后一次修复已恢复什么时候
public void onLocationChanged(Location location) {
Date dd=new Date(location.getTime());
Date ddd=new Date(System.currentTimeMillis()-(1000*60*15));
Log.e("", String.valueOf(location.getTime()+":"+System.currentTimeMillis()+":"+dd+":"+ddd));
if (dd.compareTo(ddd)==1?true:false) {
got=true;
latitude=String.valueOf(location.getLatitude());
longitude=String.valueOf(location.getLongitude());}
}