我正在尝试定期获取位置,但我获得了设备上的位置,但无法获得阿尔卑斯山x01手表上的位置。
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, MainActivity.this);
}
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, MainActivity.this);
}
@Override
public void onLocationChanged(Location location) {
Log.d("location","lat = " + location.getLatitude() + " lng = " + location.getLongitude());
Toast.makeText(MainActivity.this, "lat = " + location.getLatitude() + " lng = " + location.getLongitude(), Toast.LENGTH_SHORT).show();
}
清单:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />