Java 如何在用户行走时记录路线
我正在开发一个需要记录用户路线的应用程序。我只知道如何记录起点,但我不知道如何做其余的。请帮忙 我的工作:Java 如何在用户行走时记录路线,java,android,google-maps,gps,Java,Android,Google Maps,Gps,我正在开发一个需要记录用户路线的应用程序。我只知道如何记录起点,但我不知道如何做其余的。请帮忙 我的工作: ArrayList<LatLng> routeLatlng = new ArrayList<LatLng>(); Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); routeLatlng.add(new LatLng
ArrayList<LatLng> routeLatlng = new ArrayList<LatLng>();
Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
routeLatlng.add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()));
ArrayList RouteLatings=new ArrayList();
Location currentLocation=LocationServices.FusedLocationApi.getLastLocation(MGoogleAppClient);
添加(新LatLng(currentLocation.getLatitude(),currentLocation.getLatitude());
尝试覆盖onLocationChanged方法以记录路线。当用户的当前位置更改时,它会做出响应
@Override
public void onLocationChanged(Location currentLocation) {
routeLatlng.add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()));
}
你需要每5秒钟重复一次,然后获得新的位置,按顺序将其存储在一个数组中,这样你的应用程序就准备好了!正如@SrihariKaranth所说。但是使用一个位置侦听器,每当用户移动到足够远的地方,或者经过足够长的时间时,该侦听器就会调用所述方法。