use of com.google.android.libraries.maps.MapView in project google-maps by capacitor-community.
the class CapacitorGoogleMaps method create.
@PluginMethod()
public void create(PluginCall call) {
final Integer width = call.getInt("width", DEFAULT_WIDTH);
final Integer height = call.getInt("height", DEFAULT_HEIGHT);
final Integer x = call.getInt("x", 0);
final Integer y = call.getInt("y", 0);
final Float zoom = call.getFloat("zoom", DEFAULT_ZOOM);
final Double latitude = call.getDouble("latitude");
final Double longitude = call.getDouble("longitude");
final boolean liteMode = call.getBoolean("enabled", false);
final CapacitorGoogleMaps ctx = this;
getBridge().getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
LatLng latLng = new LatLng(latitude, longitude);
CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(zoom).build();
GoogleMapOptions googleMapOptions = new GoogleMapOptions();
googleMapOptions.camera(cameraPosition);
googleMapOptions.liteMode(liteMode);
if (mapViewParentId != null) {
View viewToRemove = ((ViewGroup) getBridge().getWebView().getParent()).findViewById(mapViewParentId);
if (viewToRemove != null) {
((ViewGroup) getBridge().getWebView().getParent()).removeViewInLayout(viewToRemove);
}
}
FrameLayout mapViewParent = new FrameLayout(getBridge().getContext());
mapViewParentId = View.generateViewId();
mapViewParent.setId(mapViewParentId);
mapView = new MapView(getBridge().getContext(), googleMapOptions);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getScaledPixels(width), getScaledPixels(height));
lp.topMargin = getScaledPixels(y);
lp.leftMargin = getScaledPixels(x);
mapView.setLayoutParams(lp);
mapViewParent.addView(mapView);
((ViewGroup) getBridge().getWebView().getParent()).addView(mapViewParent);
mapView.onCreate(null);
mapView.onStart();
mapView.getMapAsync(ctx);
}
});
call.resolve();
}
Aggregations