我正在通过Android开发增强现实应用程序 我需要一些关于移动设备谷歌地图设备的位置和方向的信息。
如果有任何教程解释,我怎样才能获得这些信息。
答案 0 :(得分:2)
您应该使用LocationManager和LocationListener课程。像在Google Developers API指南中一样使用它: 创建一个LocationManager类:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
使用覆盖onLocationChanged()方法创建LocationListener,每次更改位置时都会调用该方法:
// 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) {}
};
在LocationManager中注册LocationListener:
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
注意,当您使用LocationManager注册onLocationChanged()时,第一次调用onLocationChanged()