Last active
August 29, 2015 14:06
-
-
Save dmytrodanylyk/1bc99cbb57343379d871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Android Locations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final int MIN_STEP_DISTANCE = 10; // meter | |
public List<LatLng> createIntermediatePoints(@NotNull LatLng start, @NotNull LatLng end) { | |
List<LatLng> pointList = new ArrayList<LatLng>(); | |
double startLat = start.latitude; | |
double startLon = start.longitude; | |
double endLat = end.latitude; | |
double endLon = end.longitude; | |
float distance = LocationUtils.distance(start, end); | |
int totalSegments = (int) (distance / MIN_STEP_DISTANCE); | |
for (int segment = 1; segment <= totalSegments; segment++) { | |
double lat = (startLat + ((endLat - startLat) / (double) totalSegments) * segment); | |
double lon = (startLon + ((endLon - startLon) / (double) totalSegments) * segment); | |
pointList.add(new LatLng(lat, lon)); | |
} | |
return pointList; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationUtils { | |
public static float distance(@NotNull Location from, @NotNull Location to) { | |
return distance(from.getLatitude(), from.getLongitude(), to.getLatitude(), to.getLongitude()); | |
} | |
public static float distance(@NotNull LatLng from, @NotNull LatLng to) { | |
return distance(from.latitude, from.longitude, to.latitude, to.longitude); | |
} | |
public static float distance(double fromLat, double fromLon, double toLat, double toLom) { | |
float distance = 0; | |
float[] result = new float[3]; | |
Location.distanceBetween(fromLat, fromLon, toLat, toLom, result); | |
if (result.length > 1) { | |
distance = result[0]; | |
} | |
return distance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment