简体   繁体   中英

Not getting location updates

In my map application I dont seem to be getting location updates, I got in the car and started driving around but my position marker never changed on the map and even gave me a null lat and long

locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);

    String provider = locationManager.getBestProvider(criteria, true);
    if(provider == null){
        provider = LocationManager.NETWORK_PROVIDER;
    }
locationManager.requestLocationUpdates(provider, 60000, 5, this);

my onLocationChanged listener

@Override
public void onLocationChanged(Location location) {
    Logging logger = new Logging();
    logger.append("V", className, "onLocationChanged(Fine)", "Accuracy: " + location.getAccuracy());

    try {
        userLat = Double.toString(location.getLatitude());
        userLong = Double.toString(location.getLongitude());

        int mLat = (int) (location.getLatitude() * 1000000);
        int mLng = (int) (location.getLongitude() * 1000000);

        userLocation = new GeoPoint(mLat, mLng);

        if (!initialFix && mapSettingShowLoc) {
            showUserLocation(userLocation);
            initialFix = true;
        }

        if (mapSettingShowLoc) {
            showUserLocation(userLocation);
        }

    } catch (Exception e) {
        logger.append("E", className, "onLocationChanged", "Exception: " + e);
    }
}

in my onResume i register to listen again because I can start a new activity from the map

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, this);

what am I doing wrong?

我知道了,这是因为我缺少匹配的提供程序

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM