osmdroid / osmdroid

OpenStreetMap-Tools for Android
Apache License 2.0
2.91k stars 989 forks source link

Use MapView and Google MapView in same ViewGroup #642

Open kingfisherphuoc opened 7 years ago

kingfisherphuoc commented 7 years ago

I need to switch between Osmdroid Mapview and Google MapView, here the code I need to change:

// used to add Osmdroid MapView into container - frame layout
container.removeAllViews();
osmMapView = new MapView(container.getContext());
container.addView(mapView);

// used to add Google MapView
container.removeAllViews();
GoogleMapOptions googleMapOptions = new GoogleMapOptions();
googleMapOptions.mapType(GoogleMap.MAP_TYPE_SATELLITE);
mapView = new MapView(container.getContext(), googleMapOptions);
mapView.onCreate(new Bundle());
container.addView(mapView);
mapView.getMapAsync(this);

when I added the Google MapView first, then I can switch to Osmdroid MapView easily without any issue. However, the problem occurs when I try to change from osmdroid to google. Can anyone help? @spyhunter99

spyhunter99 commented 7 years ago

strange. what kind of layout are the map views in?

kingfisherphuoc commented 7 years ago

it's FrameLayout:

<FrameLayout
            android:id="@+id/mapContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
spyhunter99 commented 6 years ago

@kingfisherphuoc did you figure this out? I would suggest populating everything from a layout xml file if possible.