【发布时间】:2016-03-31 11:52:07
【问题描述】:
您好,我正在创建一个 Android 应用程序。其中我包括一个导航模块。
在这里,我想以 20 秒的间隔自动检查用户的位置,我不想放置任何按钮来触发此位置更改事件。这种方法应该像实时谷歌地图导航系统一样自动运行。我正在使用FusedLocationAPI 和LocationListener 获取用户的位置。
我已经创建了这个方法。
private void onLocationUpdate() {
lr.setInterval(20000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, lr, (com.google.android.gms.location.LocationListener) this);
}
这里lr 是LocationRequest 的对象。
请告诉我应该在哪里调用此方法。
在onLocationChanged(Location location) 下,我在用户的当前位置添加标记。
【问题讨论】:
标签: android google-maps navigation