【问题标题】:using location api in android [duplicate]在android中使用位置api [重复]
【发布时间】:2012-11-08 22:37:03
【问题描述】:
【问题讨论】:
标签:
android
geolocation
maps
location
android-location
【解决方案1】:
这还不错。关于这件事的官方Android SDK其实还不错。 Official Google Documentation on it
基本上,它使用的界面会在每种情况出现时运行功能。因此,只要位置根据触发该参数的任何参数发生更改,就会调用 onLocationChanged。另外,我建议只使用不同的提供商类型
最难的部分是距离部分。有公式可以使用经度和纬度计算距离。
来自文档:
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// 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 listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);