【问题标题】:GeoLocation issues?地理位置问题?
【发布时间】:2018-11-02 17:26:26
【问题描述】:
如何更改LocationManager 以仅获取一个位置?该应用会不断更新位置。
public void onClick(View view)
//this make the app keep update
locationManager.requestLocationUpdates("gps", 0, 0, listener);
【问题讨论】:
标签:
android
geolocation
locationmanager
locationlistener
【解决方案1】:
第一种方法是使用 locationManager.requestSingleUpdate() 而不是 locationManager.requestLocationUpdates()
或
第二种解决方案是在收到第一次更新后立即注销监听器,如下:
@Override
public void onLocationChanged(Location location) {
locationManager.removeUpdates(this);
// do something with the received location
}