The code for this post is available – here. (leave a star if you liked the repo !! )

Before trying to run this on a device, kindly scroll down and read the instructions for running this on devices. Thanks.

First let’s create a new project using the below command.

Next let’s install leaflet.

Now open up index.html (inside src directory) and add the below link to the leaflet css file.

Now open up home.html and modify it as shown below.

We have simply added a container using the div tags with id as map.

 

Open up home.ts and modify it as shown below.

This will add a map to the device.

Now let’s add geolocation. To add geolocation we can simply call the locate() function.

Open home.ts file again and modify it as shown below.

Now when you run the app, you will see that you are being taken to your location on the (or rather the location where your device is currently.

Let’s add a marker to the map as well.

Modify home.ts again as shown below.

Now we have added a featuregroup, created a marker and added the marker to the feature layer. Then we add this layer to the map.

We can similarly add shapes, markers of different colors etc., to our map.

Running it on devices:

Now if you try running this on your device you won’t get the desired features. To do that one has to install the cordova-geolocation plugin first.

Use the below command to install cordova-geolocation plugin

Run android.

Sources : https://tphangout.com/ionic-3-leaflet-maps-geolocation-markers/

https://ionicframework.com/docs/v3/native/geolocation/

 

 

En poursuivant votre navigation sur mon site, vous acceptez l’utilisation des Cookies et autres traceurs  pour réaliser des statistiques de visites et enregistrer sur votre machine vos activités pédagogiques. En savoir plus.