tyczj
tyczj

Reputation: 73741

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?

Upvotes: 1

Views: 858

Answers (1)

tyczj
tyczj

Reputation: 73741

I figured it out, it was because of the miss-matched providers that I had

Upvotes: 1

Related Questions