Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
How to get users geolocation and embed into a leaflet map

I am trying to get user's current location and implement it into my leaflet map, or just echo it with PHP.

only one problem... I dunno how to do that properly.

currently, I'm getting user location through IP address but when I host on my server it just retrieves the server location (which i need to avoid):

<?php
$query = @unserialize(file_get_contents('http://ip-api.com/php/'));
if($query && $query['status'] == 'success'){
  echo 'Your City is ' . $query['city'];
  echo '<br />';
  echo 'Your State is ' . $query['region'];
  echo '<br />';
  echo 'Your Zip Code is ' . $query['zip'];
  echo '<br />';
  echo 'Your Coordinates are ' . $query['lat'] . ', ' . $query['lon'];
}
?>

please help :) explain simply

here's the code for leaflet map:`

<!-- Map-->
    <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js" integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og==" crossorigin=""></script>
    <!-- Available tile layers-->
    <script src="js/map-layers.js"></script>
    <script src="js/map-detail.js"></script>
    <script>
        createDetailMap({
            mapId: 'detailMap',
            mapZoom: 14,
            mapCenter: [-42.40916, 172.83898],
            circleShow: true,
            circlePosition: [-42.40916, 172.83898]
        })

    </script>
<div class="text-block">
        <h5 class="mb-4">Listing location</h5>
        <div class="map-wrapper-300 mb-3">
       <div class="h-100" id="detailMap"></div>
     </div>

`

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the geolocation API from Leaflet. Here the offical tutorial.

function onLocationFound(e) {
    var radius = e.accuracy;

    L.marker(e.latlng).addTo(map)
        .bindPopup("You are within " + radius + " meters from this point").openPopup();

    L.circle(e.latlng, radius).addTo(map);
}

map.on('locationfound', onLocationFound);

map.locate({setView: true, maxZoom: 16});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!