0

Use Samsung S3 and Android Google Map V2(Using "LocationClient" to get location). It functions totally normal except

  1. Indoor, the first time location updated (not the getLastLocation() from LocationManager) is VERY VERY VERY SLOW even no updated. (GPS turn on, wifi off)

  2. Indoor, turn on WIFI (even did not connect to any hot spot) the first time location updated speed is fine.

I follow the tutorial below and the first time location update (not the getLastLocation() from LocationManager) speed is fine if outdoor.

(Google Tutorial) https://developers.google.com/maps/documentation/android/location and http://developer.android.com/training/location/receive-location-updates.html


And according google here, https://developers.google.com/maps/documentation/android/start, it said

android.permission.ACCESS_COARSE_LOCATION Allows the API to use WiFi or mobile cell data (or both) to determine the device's location.

android.permission.ACCESS_FINE_LOCATION Allows the API to use the Global Positioning System (GPS) to determine the device's location to within a very small area.

Thus, I think it should get location updated from both NETWORK and GPS.

========================

But what I got is

It(LocationClient) seems to only listen to GPS signal if only turn on GPS. And if you want location update from NETWORK, you have also to turn WIFI on.

Is this correct ?

THANKS...

========================

UPDATE

According to Google Maps Android API v2 creating a new LocationSource.

Now, I do not use "LocationClient" and set another "LocationSource" to Google Map. Now Google map can receive location updated very quickly even indoor and NO WIFI turn on.

Community
  • 1
  • 1
andrewwang1TW
  • 119
  • 3
  • 14

1 Answers1

2

Here is what I use for locationlistener, using all the same permissions as you.

private void startLocationListener() {

    userPosition.setPosition(myPosition);

    // Get the location manager
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.


            if(currLocation != null)
            {
                boolean better = isBetterLocation(location, currLocation);
                if(better)
                {

                    currLocation.set(location);
                    myPosition = new LatLng(currLocation.getLatitude(), currLocation.getLongitude());
                    userPosition.setPosition(myPosition);
                }
            }
            else
            {
                currLocation = location;
                myPosition = new LatLng(currLocation.getLatitude(), currLocation.getLongitude());
                userPosition.setPosition(myPosition);
            }

        }

        public void onStatusChanged(String provider, int status, Bundle extras) {}

        public void onProviderEnabled(String provider) {}

        public void onProviderDisabled(String provider) {}
    };


    locationManager.requestLocationUpdates(GPSPROVIDER, 5000, 0, locationListener);
    locationManager.requestLocationUpdates(NETPROVIDER, 30000, 0, locationListener);

}

protected boolean isBetterLocation(Location location, Location currentBestLocation) {
    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TIME;
    boolean isSignificantlyOlder = timeDelta < -TIME;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Check if the old and new location are from the same provider
    boolean isFromSameProvider = isSameProvider(location.getProvider(),
            currentBestLocation.getProvider());

    // Determine location quality using a combination of timeliness and accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
        return true;
    }
    return false;
}
RyPope
  • 2,495
  • 25
  • 46
  • Thanks, now I do not use "LocationClient" and turn to set another location source (the new location source comes from android Location manager, GPS_Provider and NETWORK_PROVIDER ) to Google map. And now the location update is very quickly even indoor no GPS signal and WIFI turn OFF. – andrewwang1TW Aug 10 '13 at 03:09
  • @andrewwang1TW Hey can u please help me in GPS_PROVIDER part : http://stackoverflow.com/questions/20112140/location-manager-is-not-working-without-internet – SSS Nov 22 '13 at 09:29