回答

0

您需要以正常方式從Fused Location Provider獲取用戶位置。完整的教程是在這裏:http://developer.android.com/training/location/retrieve-current.html

但基本上,當你收到你的接收器或服務中的地理圍欄事件,得到的LocationClient實例有,連接到它,並在回調,onConnected(),獲得最後已知的位置:

Location position = locationClient.getLastLocation(); 

99.9%的時間,或者更好一點,你會發現這個位置在你的地理圍欄內。

要繼續跟蹤用戶的位置更新,按照接收位置更新:在您的broadcastrecievero或服務http://developer.android.com/training/location/receive-location-updates.html

+0

嗨,只是清除我的困惑是否意味着如果我使用geofencing,我不必使用網絡或gps跟蹤用戶位置? Geofence自己呢? – 2014-09-30 05:25:08

+0

正確。 Geofence可以爲你工作。 – TonyC 2014-10-10 14:07:35

+1

locationClient.getLastLocation()返回當前位置,而不是一個觸發事件(它們接近但不相同),GeofencingEvent.getTriggeringLocation()已經存在,沒有使用已棄用的LocationClient – Zorb 2014-12-10 20:15:27

2

你得到一個GeofencingEvent,用它來獲得觸發位置

public class GeofenceTransitionsIntentService extends IntentService { 

    //[...] 

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

     Location l = geofencingEvent.getTriggeringLocation() 

    } 
    //[...] 
}