Geolocation 从地理围栏示例项目获取当前位置

Geolocation 从地理围栏示例项目获取当前位置,geolocation,location,latitude-longitude,geofencing,android-geofence,Geolocation,Location,Latitude Longitude,Geofencing,Android Geofence,我正在尝试谷歌的地理围栏示例项目。我正在正确获取进入/退出事件。但是如何从中获取用户的当前位置呢。即使在进入/退出点之后,我也希望跟踪用户位置。请帮忙。 您需要的可以以正常方式从融合位置提供程序获取用户位置。完整教程如下所示: 但基本上,当您在接收器或服务中接收到geofence事件时,在那里获取LocationClient实例,连接到它,然后在回调中,onConnected,获取最后已知的位置: Location position = locationClient.getLastLocatio

我正在尝试谷歌的地理围栏示例项目。我正在正确获取进入/退出事件。但是如何从中获取用户的当前位置呢。即使在进入/退出点之后,我也希望跟踪用户位置。请帮忙。
您需要的

可以以正常方式从融合位置提供程序获取用户位置。完整教程如下所示:

但基本上,当您在接收器或服务中接收到geofence事件时,在那里获取LocationClient实例,连接到它,然后在回调中,onConnected,获取最后已知的位置:

Location position = locationClient.getLastLocation();
99.9%的时间,或者更好一点,你会发现这个位置在你的地理围栏内


要继续跟踪用户位置更新,请按照接收位置更新进行操作:

您需要以正常方式从融合位置提供程序获取用户位置。完整教程如下所示:

但基本上,当您在接收器或服务中接收到geofence事件时,在那里获取LocationClient实例,连接到它,然后在回调中,onConnected,获取最后已知的位置:

Location position = locationClient.getLastLocation();
99.9%的时间,或者更好一点,你会发现这个位置在你的地理围栏内


要继续跟踪用户位置更新,请按照接收位置更新进行操作:

在您的BroadcastReceivero或服务中,如果您获得GeofencingEvent,请使用它获取触发位置

public class GeofenceTransitionsIntentService extends IntentService {

    //[...]

    @Override
    protected void onHandleIntent(Intent intent) {
        GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
        if (geofencingEvent.hasError()) {
            // ...
        }

        Location l = geofencingEvent.getTriggeringLocation()

    }
    //[...]
}

在你的广播接收器或服务中,你得到一个GeofencingEvent,用它来获得触发位置

public class GeofenceTransitionsIntentService extends IntentService {

    //[...]

    @Override
    protected void onHandleIntent(Intent intent) {
        GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
        if (geofencingEvent.hasError()) {
            // ...
        }

        Location l = geofencingEvent.getTriggeringLocation()

    }
    //[...]
}

嗨,为了澄清我的困惑,这是否意味着如果我使用地理围栏,我不必使用网络或gps跟踪用户位置?Geofence本身就是这样做的吗?locationClient.getLastLocation返回当前位置,但没有一个触发事件,它们很接近但不相同,GeofencingEvent.getTriggeringLocation已经存在,没有使用不推荐的LocationClientHi,只是为了澄清我的困惑,这是否意味着如果我使用Geofence,我不必使用网络或gps跟踪用户位置?Geofence本身就是这样做的吗?locationClient.getLastLocation返回当前位置,但没有一个触发了事件,它们已关闭但不相同,GeofencingEvent.getTriggeringLocation已存在,但未使用不推荐的locationClient