是否有可能从Android Wear SDK获得GPS定位? [英] Is it possible to get GPS location from Android Wear SDK?

查看:142
本文介绍了是否有可能从Android Wear SDK获得GPS定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过蓝牙连接我的三星GEAR直播来我的Andr​​oid设备。我有有效的互联网连接和放大器; GPS 我的Andr​​oid设备上启用。

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

现在,我想从穿戴式应用 GPS定位。

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

            }

但是, isGPSEnabled isNetworkEnabled 两者都返回false。

But, isGPSEnabled and isNetworkEnabled both are returning false.

这可能是什么原因?如何从穿戴式应用得到位置

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

推荐答案

Android Wear是一个正常的Andr​​oid设备。这些API返回假的,因为你的Andr​​oid Wear设备没有GPS或网络连接。

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


  1. 您可以实现通过发送手机获得的可穿戴应用GPS定位自己的GPS提供商。

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

您可以使用谷歌播放服务的位置API来获取GPS位置,因为他们使人们对磨损自动工作。这里是Google+上的帖子是证实了这一点:<一href=\"https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx\">https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx

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

要实现谷歌Play服务请按以下教程:

检索当前位置:

<一href=\"https://developer.android.com/training/location/retrieve-current.html\">https://developer.android.com/training/location/retrieve-current.html

接收位置更新:

<一href=\"https://developer.android.com/training/location/receive-location-updates.html\">https://developer.android.com/training/location/receive-location-updates.html


请注意,它应该与任何位置API的工作,所以你也可以使用类似 ActivityRecognitionApi GeofencingApi 等的API

<一href=\"https://developer.android.com/reference/com/google/android/gms/location/package-summary.html\">https://developer.android.com/reference/com/google/android/gms/location/package-summary.html

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

这篇关于是否有可能从Android Wear SDK获得GPS定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆