I have covered multiple locations in Google map
using LatLng.Builder
and it's working.
Is there any way I could cover the whole path between two location in Google map
?
My Curent Code to include multiple locations
builder = new LatLngBounds.Builder();
builder.include(LatLng1);
builder.include(LatLng2);
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 17));
Any suggestion please?
Thanks
I know you already find the answer, but here is my method to solve the problem
boolean hasPoints = false;
Double maxLat = null, minLat = null, minLon = null, maxLon = null;
if (polyline != null && polyline.getPoints() != null) {
List<LatLng> pts = polyline.getPoints();
for (LatLng coordinate : pts) {
// Find out the maximum and minimum latitudes & longitudes
// Latitude
maxLat = maxLat != null ? Math.max(coordinate.latitude, maxLat) : coordinate.latitude;
minLat = minLat != null ? Math.min(coordinate.latitude, minLat) : coordinate.latitude;
// Longitude
maxLon = maxLon != null ? Math.max(coordinate.longitude, maxLon) : coordinate.longitude;
minLon = minLon != null ? Math.min(coordinate.longitude, minLon) : coordinate.longitude;
hasPoints = true;
}
}
if (hasPoints) {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(maxLat, maxLon));
builder.include(new LatLng(minLat, minLon));
map.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 48));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With