0

使用 Samsung S3 和 Android Google Map V2(使用“LocationClient”获取位置)。它的功能完全正常,除了

  1. 在室内,第一次更新位置(不是来自 LocationManager 的 getLastLocation())非常非常慢,甚至没有更新。(GPS打开,wifi关闭)

  2. 室内,打开WIFI(甚至没有连接任何热点)第一次位置更新速度还可以。

我按照下面的教程进行了第一次位置更新(不是来自 LocationManager 的 getLastLocation())速度在户外时很好。

(谷歌教程) https://developers.google.com/maps/documentation/android/locationhttp://developer.android.com/training/location/receive-location-updates.html


根据谷歌这里,https://developers.google.com/maps/documentation/android/start,它说

android.permission.ACCESS_COARSE_LOCATION 允许 API 使用 WiFi 或移动蜂窝数据(或两者)来确定设备的位置。

android.permission.ACCESS_FINE_LOCATION 允许 API 使用全球定位系统 (GPS) 在非常小的区域内确定设备的位置。

因此,我认为它应该从 NETWORK 和 GPS 更新位置。

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

但我得到的是

如果只打开 GPS,它(LocationClient)似乎只听 GPS 信号。如果您想从 NETWORK 更新位置,您还必须打开 WIFI。

这个对吗 ?

谢谢...

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

更新

根据Google Maps Android API v2 创建一个新的 LocationSource

现在,我不使用“LocationClient”并将另一个“LocationSource”设置为 Google Map。现在谷歌地图可以接收更新的位置非常快,即使是在室内并且没有 WIFI 开启。

4

1 回答 1

2

这是我用于 locationlistener 的内容,使用与您相同的权限。

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;
}
于 2013-08-10T02:33:13.537 回答