Thank you for your tips. I managed to add "zoom to path" functionality, ie moving camera such that the entire specified path is visible and centered on screen with maximum possible zoom. But there are some glitches. I'm using Samsung Galaxy Trend with Android 4.0.4.
Every second time form with native MapContainer is not showing properly (look at the attached photo. Why not screenshot? Because when I take screenshot, it contains form from which map form was invoked). On the photo you can see that previous form is visible through places where normally zoom controls and Google logo are seen (marked with red rectangles). Small part is visible also on the top of the photo. When I rotate phone, screen gets refreshed and I can see form from which I was invoking map form. So it looks like map form is drawn, but focus is set to previous form (map is not static, I can see that it is loading tiles). Code:
IntenalNativeMapsImpl.java (for Android):
public void createBoundsBuilder() {
//AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() { //tried that with no luck
//public void run() {
boundsBuilder = LatLngBounds.builder();
// }
//});
}
public void extendBounds(final double lat, final double lon) {
// AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() { //tried that with no luck
// public void run() {
boundsBuilder.include(new LatLng(lat, lon));
// }
//});
}
public void fitBounds() {
final LatLngBounds bounds = boundsBuilder.build();
AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
public void run() {
mapInstance.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 20));
}
});
MapContainer.java:
public void fitBounds(Coord... path) {
if (isNativeMaps()) {
internalNative.createBoundsBuilder();
for(Coord c : path) {
internalNative.extendBounds(c.getLatitude(), c.getLongitude());
}
internalNative.fitBounds();
} else {
this.zoom(path[0], this.getMaxZoom());
}
}
I tried invoking fitBounds() before and after map show but effect is always pretty much the same. Map Form and MapContainer are created once and reused. When I am using mapContainer.zoom(Coord, zoom) instead then everything is working fine. Do you have any ideas?