如何在Android中使用FusedLocationApi时获取位置模式

时间:2016-01-05 06:19:57

标签: java android

我使用以下代码来获取用户的位置。

LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);

这会返回一个android.location.Location对象,我可以成功获得纬度和经度但是当我尝试获取模式时,它会让我“融合”。

我想知道获取位置的模式是使用GPS还是网络。

2 个答案:

答案 0 :(得分:0)

如果你想检查gps和网络提供商使用以下代码。我不认为使用融合api我们能够区分它

public Location getLocation() {
    try {
        locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);

        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if(!isGPSEnabled && !isNetworkEnabled) {

        } else {
            this.canGetLocation = true;

            if (isNetworkEnabled) {

                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                    if (location != null) {

                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }

            }

            if(isGPSEnabled) {
                if(location == null) {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    if(locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                        if(location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

答案 1 :(得分:0)

您可以确定使用准确度。如果准确度很高,则来自GPS。