配置清单以捕获可用的新位置

时间:2011-11-07 13:35:04

标签: android gps broadcastreceiver

如何配置清单以捕获新的位置坐标? 我可以使用BroadcastReceiver来捕获新坐标吗?

2 个答案:

答案 0 :(得分:1)

如果你在清单的应用程序元素中添加它,只要获得新的gps坐标,它就会在你的LocationChangedReceiver类中调用onReceive:

<receiver android:name=".location.LocationChangedReceiver" />

LocationChangedReceiver可能如下所示:

public class LocationChangedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String locationKey = LocationManager.KEY_LOCATION_CHANGED;

        if (intent.hasExtra(locationKey)) {
            Location location = (Location) intent.getExtras().get(locationKey);
            Log.d(TAG, "Got Location! Lat:" + location.getLatitude() + ", Lon:" + location.getLongitude() + ", Alt:" + location.getAltitude() + ", Acc:" + location.getAccuracy());

            return;
        }

    }
}

答案 1 :(得分:0)

如果我理解正确,您可能会发现passive provider有帮助。

有用的