2012-03-08 72 views
0

我正在使用被動提供商,使用此代碼。Google地圖和被動提供商

Intent intent = new Intent(PASSIVE_ACTION); 
PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, pi); 

和我在AndroidManifest.xml限定廣播接收機

<receiver 
    android:name="passiveLocationReceiver" 
    android:enabled="true" > 
     <intent-filter> 
      <action android:name="com.passive_location_update" /> 
     </intent-filter> 
</receiver> 

passiveLocationReceiver是

public class passiveLocationReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     if (!PASSIVE_ACTION.equals(action)) 
      return; 

     Log.d("chitacan","Passive Provider Event!!!"); 
     } 
    } 

此代碼工作正常時其他地理位置應用程序(臉譜,四角..等) 但是使用「Google Map」應用程序,它不會。(d.android.com解釋「PASSIVE_PROVIDER」,當其他應用程序可以更新時equests位置。)

即使我可以看到我的位置。「谷歌地圖」應用程序,但我無法擺脫被動提供商的任何事件。(我不能看到passiveLocationReceiver的日誌信息。)

好,我試圖在命令行轉儲LocationManager的狀態,

$adb shell dumpsys location 

但是LocationManager的狀態沒有改變任何東西。似乎「Google地圖」應用程序 未使用LocationManager。

有沒有什麼辦法讓被動活動時,「谷歌地圖」應用程序更新我的位置? 還是我做錯了什麼?

回答

0

requestLocationUpdates將只接收位置值的更改或「更新」。 Google地圖將廣播由GPS位置提供商提供的位置值更改。

如果從模擬器測試,嘗試輸入你的模擬位置的新值。否則,在四處走動時進行測試。

不過,我注意到太那個的Wi-Fi(網絡)位置的變化不是廣播從谷歌地圖一樣,他們是從其他類似的應用程序。

在你的個案可能是GPS未啓用,或者它不是來自它的當前狀態改變位置,因此你是不是在位置接收到任何「更新」到這個監聽器。 (我發現這個話題,因爲我想知道爲什麼谷歌地圖沒有廣播Wi-Fi位置的變化,如果有人數字了這一點)

2

最近的谷歌地圖等地圖服務使用基於谷歌播放服務位置API的新版本。他們不僅僅依靠GPS或網絡提供商,而是使用「Fused」。出於這個原因,傳統的PASSIVE_PROVIDER無法使用「融合」方法捕獲位置更新。

你最好使用帶有LocationClient和LocationRequest與PRIORITY_NO_POWER新的API。請檢查以下代碼

 LocationRequest lRequest = LocationRequest.create() 
               .setPriority(LocationRequest.PRIORITY_NO_POWER) 
               .setInterval(mMIN_LOCATION_UPDATE_INTERVERAL_IN_MILLISECONDS); 

    Intent locationIntent = new Intent(mPASSIVE_LOCATION_INTENT_ACTION_STRING); 
    mPassiveLocationPendingIntent = PendingIntent.getBroadcast(mContext, 0, locationIntent ,PendingIntent.FLAG_UPDATE_CURRENT); 
    mPassiveLocationClient.requestLocationUpdates(lRequest, mPassiveLocationPendingIntent); 
+0

...但是,您無法確定位置是來自GPS或網絡還是具有融合位置的WiFi。 – 2014-12-12 15:14:25