Skip to content

Commit

Permalink
fixed location object in snapToRoute (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Mace authored Oct 27, 2017
1 parent 43bc4a3 commit 49eddb1
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class SnapToRoute extends Snap {
@Override
public Location getSnappedLocation(Location location, RouteProgress routeProgress,
@Nullable List<Point> coords) {
location = snapLocationLatLng(location, coords);
location.setBearing(snapLocationBearing(routeProgress));
return location;
Location snappedLocation = snapLocationLatLng(location, coords);
snappedLocation.setBearing(snapLocationBearing(routeProgress));
return snappedLocation;
}

/**
Expand All @@ -43,19 +43,19 @@ public Location getSnappedLocation(Location location, RouteProgress routeProgres
* @return the altered user location
* @since 0.4.0
*/
private static Location snapLocationLatLng(Location location,
List<Point> coords) {
private static Location snapLocationLatLng(Location location, List<Point> coords) {
Location snappedLocation = new Location(location);
Point locationToPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());

// Uses Turf's pointOnLine, which takes a Point and a LineString to calculate the closest
// Point on the LineString.
if (coords.size() > 1) {
Feature feature = TurfMisc.pointOnLine(locationToPoint, coords);
Point point = ((Point) feature.geometry());
location.setLongitude(point.longitude());
location.setLatitude(point.latitude());
snappedLocation.setLongitude(point.longitude());
snappedLocation.setLatitude(point.latitude());
}
return location;
return snappedLocation;
}

private static float snapLocationBearing(RouteProgress routeProgress) {
Expand Down

0 comments on commit 49eddb1

Please sign in to comment.