2012-03-08 31 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