我已经通过蓝牙
连接我的三星GEAR直播
来我的Android设备。我有有效的互联网连接和放大器; GPS
我的Android设备上启用。
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是一个正常的Android设备。这些API返回假的,因为你的Android 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.
您可以实现通过发送手机获得的可穿戴应用GPS定位自己的GPS提供商。
You can implement your own "GPS provider" that sends gps position obtained by a phone to your to Wearable app.
您可以使用谷歌播放服务的位置API来获取GPS位置,因为他们使人们对磨损自动工作。这里是Google+上的帖子是证实了这一点: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服务请按以下教程:检索当前位置: https://developer.android.com/training/location/retrieve-current.html接收位置更新: https://developer.android.com/training/location/receive-location-updates.html请注意,它应该与任何位置API的工作,所以你也可以使用类似 ActivityRecognitionApi
, GeofencingApi
等的API 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