William Seemann
William Seemann

Reputation: 3529

Finding Union of LatLngBounds in Google Maps for Android

Is it possible to find the Union of two LatLngBounds in Google Maps for Android. I can't seem to locate a method in the documentation to accomplish this. Thanks in advance.

Upvotes: 0

Views: 893

Answers (2)

Maxime Claude
Maxime Claude

Reputation: 995

Antonio's answer displayed only bounds1 for me. What worked was the use of LatLng.Builder:

LatLngBounds bounds1 = new LatLngBounds(new LatLng(8.2,48.2), new LatLng(8.1,47.2));
LatLngBounds bounds2 = new LatLngBounds(new LatLng(8.1,48.1), new LatLng(8.0,47.1));
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();

boundsBuilder.include(bounds1.northeast);
boundsBuilder.include(bounds1.southwest);

boundsBuilder.include(bounds2.northeast);
boundsBuilder.include(bounds2.southwest);

LatLngBounds unionBounds = boundsBuilder.build();

Upvotes: 0

antonio
antonio

Reputation: 18262

You just need to add one of your LatLngBounds``northeast and southwest coordinates to the other LatLngBounds using the including method:

LatLngBounds bounds1 = new LatLngBounds(new LatLng(8.2,48.2), new LatLng(8.1,47.2));
LatLngBounds bounds2 = new LatLngBounds(new LatLng(8.1,48.1), new LatLng(8.0,47.1));

// Expand bounds1 to include bounds2
bounds1.including(bounds2.northeast);
bounds1.including(bounds2.southwest);

Upvotes: 2

Related Questions