0

当接近警报触发时,我正在使用以下代码来确定当前位置:

Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null) {
    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    if (location == null) {
        // We'll just write an empty location
        location = new Location("");
    }
}

当我查看返回的位置时,我会在不应该收到警报的位置输入警报。我的印象是接近警报在内部轮询 GPS 和网络提供商 - 从而更新 LastKnownLocation - 此代码将产生当前位置。这个假设正确吗?

4

1 回答 1

1

我正在使用以下代码来确定当前位置及其工作。查看dis代码...

        LocationManager locationManager;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager) getSystemService(context);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = locationManager.getBestProvider(criteria, true);

        if (null != provider) 
        {
            Location location = locationManager.getLastKnownLocation(provider);
            if (null != location) {
                GpsFound=true;
                currentLat = location.getLatitude();
                currentLon = location.getLongitude();
                System.out.println("Current Lat,Long :"+currentLat+" ,"+currentLon);
            }
            else
            {
                //GpsFound=false;
                gpsMsg="Current Location can not be resolved!";
            }

        } 
        else 
        {
            gpsMsg="Provider is not available!";
            //GpsFound=false;
        }
于 2011-10-10T04:08:17.573 回答