我怎样才能获得移动方向
i'm developing an augmented reality application by android and i need some information about the location and direction of device from google map in mobile .
我正在开发一个由Android增强现实应用程序,我需要一些关于设备的位置和方向从谷歌地图移动中的信息。
how can i get those information , if there's any tutorial explain that .
如果有任何教程解释,我怎样才能获得这些信息。
1 个解决方案
#1
2
You should use LocationManager and LocationListener classes. Use it like at Google Developers API Guide: create a LocationManager class:
您应该使用LocationManager和LocationListener类。像在Google Developers API指南中一样使用它:创建一个LocationManager类:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Create LocationListener with overriding onLocationChanged() method, that calls every time you change location:
创建LocationListener并覆盖onLocationChanged()方法,每次更改位置时调用:
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
Register the LocationListener in LocationManager:
在LocationManager中注册LocationListener:
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Notice, onLocationChanged() is called at the first time, when you register it with LocationManager
注意,当您使用LocationManager注册onLocationChanged()时,第一次调用onLocationChanged()