GPS-Standort wird bereitgestellt jede Sekunde, was für ein reibungsloses Erlebnis offensichtlich nicht ausreicht.
Ich dachte, ich könnte zwischen den letzten beiden angegebenen Standorten interpolieren, die Markierungsposition aktualisieren und die Karte alle 16 ms verschieben, um von jedem angegebenen Standort aus einen Übergang mit 60 Bildern pro Sekunde zu erstellen Dies führt zu einer reibungslosen Bewegung.
Das Problem ist, dass dies unerträglich viel Batterie verbraucht und einen Emulator 70 % der PC-CPU beansprucht.
Ich habe versucht, es auf 20 oder sogar 10 fps zu ändern, aber nicht viel Unterschied.
Die Waze-Anwendung bietet genau das, was ich anstrebe, und benötigt dabei 30–40 % CPU.
Irgendwelche Ideen, wie man das erreichen kann, ohne das Telefon zu überfordern?
Dies ist mein aktueller Code, der benötigt wird viel CPU:
Code: Select all
if(fusedLocationClient != null && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED)
{
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Location location = locationResult.getLastLocation();
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
if(mLastLocation == null)
{
mLastLocation = latLng;
mCurrLocationMarker = Helper.setCustomMarker(MapsActivity.this, latLng, mMap);
locationUpdater = new LocationUpdater(mMap, MapsActivity.this, mCurrLocationMarker);
}
mCurrLocationMarker.setRotation(calculateBearing(mLastLocation, latLng));
//mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,18), ANIMATION_TIME, null);
animateMarker(mLastLocation, latLng);
mLastLocation = latLng;
//move map camera
}
};
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setInterval(ANIMATION_TIME);
locationRequest.setFastestInterval(ANIMATION_TIME/2);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper());
}
public void animateMarker(final LatLng startPosition, final LatLng toPosition) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final long duration = ANIMATION_TIME;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * toPosition.longitude + (1 - t)
* startPosition.longitude;
double lat = t * toPosition.latitude + (1 - t)
* startPosition.latitude;
LatLng latLng = new LatLng(lat, lng);
mCurrLocationMarker.setPosition(latLng);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,18));
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}```