Menu
Close

Lat Lng to Digipin

Sample Implementation

    
      
      <html>
        <head>
          <title>Lat Lng to Digipin</title>
          <meta name="viewport" content="initial-scale=1.0">
          <meta charset="utf-8">
          <style>
          html,
          body,
          #map {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100vh;
          }
          #auto {
            width: 315px;
            position: absolute;
            z-index: 999;
            font-size: 15px;
            padding: 10px;
            border: 1px solid #ddd;
            outline: none !important;
            top: 5px;
            border-radius: 10px;
            margin: 4px;
          }
          #search-btn {
            position: absolute;
            top: 5px;
            left: 320px;
            cursor: pointer;
            z-index: 999;
            font-size: 14px;
            padding: 10px;
            border: 1px solid #000000;
            outline: none !important;
            border-radius: 10px;
            margin: 6px;
          }
          #result {
            width: 300px;
            background-color: #fff;
            position: absolute;
            z-index: 999;
            font-size: 15px;
            font-weight: bold;
            padding: 10px;
            top: 50px;
            border-radius: 10px;
            margin: 4px;
          }
                         
          </style>
               <script src="https://apis.mappls.com/advancedmaps/api/<Token>/map_sdk?layer=vector&v=3.0&libraries=digipin&callback=initMap1"></script>
            </head>
        <body>
            <input type="text" id="auto" name="auto" class="search-outer form-control as-input" placeholder="Enter Lat & Lng" required="" spellcheck="false">
            <div id="map"></div>
            <button onclick="createMarker()" type="button" id="search-btn">Search</button>
            <div id="result"></div>
                        <script>
        var map, marker = null,
            Marker1;
        var input = document.getElementById('auto');
        input.value = '28.550705, 77.268960';
        
        function initMap1() {
            map = new mappls.Map('map', {
                center: [28.09, 78.3],
                zoom: 5
            });

            function createMarker() {
                let latLng = input.value;
                let lat, lng;
                if (latLng) {
                    const coordinates = latLng.split(',');
                    mappls.remove({
                        map: map,
                        layer: Marker1
                    });
                    Marker1 = new mappls.Marker({
                        map: map,
                        position: {
                            "lat": parseFloat(coordinates[0]),
                            "lng": parseFloat(coordinates[1])
                        },
                        fitbounds: true,
                        icon_url: 'https://apis.mapmyindia.com/map_v3/1.png'
                    });
                    const digi = mappls.latlngToDigipin(coordinates[0], coordinates[1]);
                    if (digi) {
                        document.getElementById("result").innerHTML = 'Digipin: ' + digi;
                    }
                } else {
                    document.getElementById("result").innerHTML = 'Please enter coordinates.';
                }
            }
            document.getElementById('search-btn').addEventListener('click', createMarker);
        }
    </script>

        </body>
      </html>
      
      
      
    
  
Call at Mappls
Request Call Back

Personalisation SDK, by Mappls, is India's first O2O engagement tool that can 3X your customer engagement, retention and conversion.

There's so much that Mappls MapmyIndia can do for your enterprise or individual requirements. Explore our website to learn more or request a callback/email if you'd like us to connect with you.

or