Hi!
I have an app using ionic with vuejs and i add in my project a page with a map using the @capacitor/google-maps plugin.
This problem only appear on android (not tested on IOS) and works fine on web.
This map works fine if i don’t surround it with ion-content tag but since i add it the map disappear.
I want to use the ion-content tag cause i have an ion-header with a back button and if i don’t use the ion-content tag the button isn’t trigger when i click on it, cause the map is in background and interpret this event by an action on the map.
Here I show you the map working without ion-content tag.
<ion-page>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button default-href="/tabs/home" text="" color="primary"></ion-back-button>
</ion-buttons>
<ion-title> Map </ion-title>
</ion-toolbar>
</ion-header>
<capacitor-google-map :id="mapID"></capacitor-google-map>
</ion-page>
Here you have the result with the ion-content:
<ion-page>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button default-href="/tabs/home" text="" color="primary"></ion-back-button>
</ion-buttons>
<ion-title> Map </ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<capacitor-google-map :id="mapID"></capacitor-google-map>
</ion-content>
</ion-page>
I can see in the log that the map is successfully created, i have no errors on any console.
Here is a sample of my code.
<script setup>
import {
IonHeader,
IonContent,
IonTitle,
IonToolbar,
IonButtons,
IonBackButton,
IonPage,
onIonViewWillEnter,
} from '@ionic/vue';
import { GoogleMap } from '@capacitor/google-maps';
const mapID = 'mapPage';
const apiKey = process.env.VUE_APP_GOOGLE_MAPS_API;
onIonViewWillEnter(() => {
mapInit(mapID);
})
async function mapInit(mapID) {
this.map = await GoogleMap.create({
id: mapID,
element: document.getElementById(mapID),
apiKey: apiKey,
config: {
center: {
lat: 33.6,
lng: -117.9,
},
zoom: 13,
disableDefaultUI: true,
clickableIcons: false,
},
});
}
</script>
<template>
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button default-href="/tabs/home" text="" color="primary"></ion-back-button>
</ion-buttons>
<ion-title> Map </ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<capacitor-google-map :id="mapID"></capacitor-google-map>
</ion-content>
</ion-page>
</template>
<style scoped>
capacitor-google-map {
display: inline-block;
width: 100%;
height: 100%;
}
ion-content {
--background: transparent !important;
}
</style>
Someone have any idea from where this error came from ?
Thanks for your help!