0
this.map = leaflet.map("mapId", { zoomControl: false }).setView([17.385, 78.4867], 13);
      leaflet.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
        attribution: '',
      }).addTo(this.map);
      this.map.locate({
        setView: true,
        maxZoom: 11
      })

We have tried implementing the above code. It is working fine in online mode but does not work when offline. How can we implement current location & search locations functionality in leaflet maps when offline? Anyone who integrated offline leaflet maps with Ionic + Angular, please provide a solution. Thanks in advance.

1 Answer 1

0

So let's clear things. If you want an offline map in Angular with Ionic READ THIS BLOG POST

Then if you want an implementation of the current location you should use Geolocation Cordova Plugin and as they say :

This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi, and Bluetooth MAC addresses, and GSM/CDMA cell IDs.

To search locations by name fragment You should store the locations name in the database with the corresponding pair of coordinates like

// KEY : NAME OF LOCATION : VALUE [LATITUDE, LONGITUDE]
object: {[key: string]:[number,number] } = {"USA":[37.6000,-95.6650]};

then you will be able to search coordinates by their location name.

3
  • Hey ! Thanks for your quick reply. But we want solution in Ionic + Angular. Commented Aug 2, 2021 at 8:38
  • May we can't provide you a fully functional solution to this. But with a little refactoring, you can grab that code and use it in Angular. But I'm on it and I try to dynamically update my Answer Commented Aug 2, 2021 at 8:40
  • davidrs.com/wp/phonegap-3-0-leaflet-offline-maps Unfortunately, this demo is not working for us and showing 404 error for images. Commented Aug 2, 2021 at 9:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.