我是Android新手,我正在開發地理圍欄項目。如何從公開列表中檢索觸發的地理柵欄的經度和緯度<Geofence> getTriggeringGeofences()
是否有可能從公共列表getTriggeringGeofences()檢索觸發的地理柵欄的經度和緯度?
我希望在地圖上顯示觸發的位置,一旦我們收到通知提醒並且用戶點擊了通知。點擊通知後,將顯示帶有所有觸發的地理欄位的mapActivity。 要添加標記,我需要觸發位置的LatLong。我該如何實現?
我是Android新手,我正在開發地理圍欄項目。如何從公開列表中檢索觸發的地理柵欄的經度和緯度<Geofence> getTriggeringGeofences()
是否有可能從公共列表getTriggeringGeofences()檢索觸發的地理柵欄的經度和緯度?
我希望在地圖上顯示觸發的位置,一旦我們收到通知提醒並且用戶點擊了通知。點擊通知後,將顯示帶有所有觸發的地理欄位的mapActivity。 要添加標記,我需要觸發位置的LatLong。我該如何實現?
你可以從IntentService地理圍欄事件
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(意向)的緯度和經度;
在意圖服務是將地理圍欄被觸發,所以你會在這裏添加引腳:
public class GeofenceTransitionsIntentService extends IntentService {
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
List triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
Android的官方文件對實施地理圍欄一個很好的教程:
https://developer.android.com/training/location/geofencing.html
你可以從GeofencingEvent獲取它。
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
//TODO: Error handling
return;
}
Location location = geofencingEvent.getTriggeringLocation();
double latitude = location.getLatitude();
double longitude = location.getLongitude();
}
是的,我使用了同樣的方法。我想知道我們是否可以從每個地理圍欄中單獨提取緯度和緯度。 例如:geofence.getRequestId()單獨返回請求ID。登錄以下 我們可以從地理圍欄經緯度提取類似的方式: 地理柵欄[CIRCLE ID:衛星鄉鎮轉變:1 10.006100,76.331200 1000米RESP = 0,停留= -1ms,@ 187017824] 我需要的轉換:1 10.006100 ,僅76.331200部分。 –