【发布时间】:2017-09-14 12:23:26
【问题描述】:
我需要在单击按钮时立即将当前位置返回给服务器。
mFusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
// ...
}
}
});
在 Android 文档中,建议使用这种方式来获取位置。但如您所见,它不会立即返回该位置。我应该等待thread.sleep() 或相关的东西直到onSuccess 运行?或者最好的方法是什么?
【问题讨论】:
标签: java android geolocation