是否可以从Android Wear SDK获取GPS位置?

时间:2014-07-20 09:07:28

标签: android wear-os

我已通过Samsung GEAR Live将我的bluetooth与我的Android设备相关联。我有活跃的互联网连接和我的Android设备已启用GPS

现在,我正在尝试从Wearable App获取GPS位置。

LocationManager locationManager = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
            // getting GPS status
            boolean isGPSEnabled = locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
            // getting network status
            boolean isNetworkEnabled = locationManager
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            if (isGPSEnabled == false && isNetworkEnabled == false) {
                location = null;
            } else if (isGPSEnabled) {
                location = locationManager
                        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            }
            if (isNetworkEnabled && location == null) {
                location = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            }

但是,isGPSEnabledisNetworkEnabled都返回false。

可能是什么原因?如何从Wearable App获取位置?

1 个答案:

答案 0 :(得分:6)

Android Wear是一款普通的Android设备。这些API返回false,因为您的Android Wear设备没有GPS或网络连接。

  1. 您可以实施自己的" GPS提供商"将手机获取的gps位置发送到您的可穿戴应用程序。

  2. 您可以使用Google Play服务位置API获取GPS位置,因为它们已在Wear上自动运行。以下是Google+上的一篇帖子,其中确认了这一点:https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx

  3. 要实施Google Play服务,请遵循以下教程:
    检索当前位置
    https://developer.android.com/training/location/retrieve-current.html
    接收位置更新:
    https://developer.android.com/training/location/receive-location-updates.html

    请注意,它应该适用于任何Location API,因此您也可以使用ActivityRecognitionApiGeofencingApi等API。 https://developer.android.com/reference/com/google/android/gms/location/package-summary.html