Is it possible to get GPS location from Android Wear SDK?

北城余情 提交于 2019-12-12 10:12:53

问题


I have connected my Samsung GEAR Live to my Android device through bluetooth. I have active internet connection & GPS enabled on my Android device.

Now, I am trying to get the GPS location from Wearable App.

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);

            }

But, isGPSEnabled and isNetworkEnabled both are returning false.

What could be the reason? How to get the location from Wearable App ?


回答1:


Android Wear is a normal Android device. These API returns false because your Android Wear device doesn't have GPS or network connection.

  1. You can implement your own "GPS provider" that sends gps position obtained by a phone to your to Wearable app.

  2. You can use Google Play services Location API to obtain GPS position because they have made it work automatically on Wear. Here is a post on Google+ that confirms this: https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx

To implements Google Play services please follow these tutorials:
Retrieving the Current Location:
https://developer.android.com/training/location/retrieve-current.html
Receiving Location Updates:
https://developer.android.com/training/location/receive-location-updates.html

Please notice that it should work with any of Location API so you can also use APIs like ActivityRecognitionApi, GeofencingApi etc.
https://developer.android.com/reference/com/google/android/gms/location/package-summary.html



来源:https://stackoverflow.com/questions/24848970/is-it-possible-to-get-gps-location-from-android-wear-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!