Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MapsActivity.java #17

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions app/src/main/java/com/developers/uberanimation/MapsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,28 @@ public void run() {
JourneyEventBus.getInstance().setOnJourneyEnd(endJourneyEvent);
}
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(3000);
valueAnimator.setDuration(2000);
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
v = valueAnimator.getAnimatedFraction();
lng = v * endPosition.longitude + (1 - v)
* startPosition.longitude;
lat = v * endPosition.latitude + (1 - v)
* startPosition.latitude;
LatLng newPos = new LatLng(lat, lng);

// lng = v * endPosition.longitude + (1 - v)
// * startPosition.longitude;
// lat = v * endPosition.latitude + (1 - v)
// * startPosition.latitude;

LatLng newPos = GoogleMapUtil.interpolate(startPosition, endPosition, v);

// LatLng newPos = new LatLng(lat, lng);
CurrentJourneyEvent currentJourneyEvent = new CurrentJourneyEvent();
currentJourneyEvent.setCurrentLatLng(newPos);
JourneyEventBus.getInstance().setOnJourneyUpdate(currentJourneyEvent);
marker.setPosition(newPos);
marker.setAnchor(0.5f, 0.5f);
marker.setRotation(getBearing(startPosition, newPos));
// marker.setRotation(getBearing(startPosition, newPos));
marker.setRotation(GoogleUtil.computeHeading(startPosition, endPosition);
mMap.animateCamera(CameraUpdateFactory.newCameraPosition
(new CameraPosition.Builder().target(newPos)
.zoom(15.5f).build()));
Expand All @@ -311,38 +316,39 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {
}, 3000);
}

public List<LatLng> decode(String encodedPath) {
int len = encodedPath.length();
List<LatLng> path = new ArrayList();
int index = 0;
int lat = 0;
int lng = 0;

private List<LatLng> decodePoly(String encoded) {
List<LatLng> poly = new ArrayList<>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
while(index < len) {
int result = 1;
int shift = 0;

while (index < len) {
int b, shift = 0, result = 0;
int b;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
b = encodedPath.charAt(index++) - 63 - 1;
result += b << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
} while(b >= 31);

lat += (result & 1) != 0 ? ~(result >> 1) : result >> 1;
result = 1;
shift = 0;
result = 0;

do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
b = encodedPath.charAt(index++) - 63 - 1;
result += b << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
} while(b >= 31);

LatLng p = new LatLng((((double) lat / 1E5)),
(((double) lng / 1E5)));
poly.add(p);
lng += (result & 1) != 0 ? ~(result >> 1) : result >> 1;
path.add(new LatLng((double)lat * 1.0E-5D, (double)lng * 1.0E-5D));
}

return poly;
return path;
}

private float getBearing(LatLng begin, LatLng end) {
Expand Down