Google Maps & Geolocation
Using Google Maps in an Ionic 5 app
Last updated
Was this helpful?
Using Google Maps in an Ionic 5 app
Last updated
Was this helpful?
This feature is only available in the PRO version.
We will use the Google Maps Javascript SDK to embed a map in our app.
First of all, you need to . It's super simple to do it, just follow the steps from the . Make sure to enable the Maps JavaScript API.
Once you have your KEY, go to the index.html
file and at the end you will see the following script. You need to replace YOUR_GOOGLE_MAPS_KEY with your own KEY.
You need to install @types/googlemaps. This package contains type definitions for Google Maps JavaScript API.
We created a GoogleMapComponent
that you can find in src/app/components/google-map/google-map.component.ts
that will do the magic for you.
This component has the map and the logic to init the map. So, from the page you want to show you map you will add a reference to it:
If you experience this error @types/googlemaps/index.d.ts is not a module then do the following.
npm install @types/googlemaps --save-dev
add "types": ["googlemaps"]
in tsconfig.app.json
file in compilerOptions.
remove import {} from 'googlemaps';
from your code.
For this feature we use the to get the current position of the device and then we show a marker in the map.