Liste des Poi – Open Street Map

Liste des Poi – Open Street Map

En premier lieu je vous donne cette fonction en PHP

<?php
function searchAmenity($amenity,$lat1,$long1){
   $overpass = 'https://www.overpass-api.de/api/interpreter?data=[out:json];node[amenity='.$amenity.'](around:3000,'.$lat1.','.$long1.');out;';
   $html = file_get_contents($overpass);
   $result = json_decode($html, true);
   $data = $result['elements'];
   $returnArray = '';
   $i = '0';
   foreach($data as $key => $row) {
       if(strlen($row['tags']['name']) > '3'){
           $i++;
           $returnArray .= '["'.$row['tags']['name'].'",'.$row['lat'].','.$row['lon'].'], ';
       }
       $longitudeFixe = $row['lon'];
       $latitudeFixe = $row['lat'];
   }
   return $returnArray;
}
?>

Cette fonction est pour la récupération des voisinages autour de 3 KM

Un exemple complet sur l’utilisation, on a fait une recherche sur les pharmacies.

<link  rel="stylesheet"  href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"></script>
<div id="map"></div>
<script>
    var map = L.map('map').setView([50.82914394480393, 4.324493408203125], 14);
    mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
    L.tileLayer(
        'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; ' + mapLink + ' Contributors',
        maxZoom: 15,
        }
    ).addTo(map);
    /* BEGIN PHARMACIE */
    var planesPharmacie = [
        <?= searchAmenity('pharmacy','50.82914394480393','4.324493408203125'); ?>
    ];
    var PharmacieIcon = L.icon({
        iconUrl: 'URL_ICONE',
        iconSize: [30, 40],
    });
    for (var i = 0; i < planesPharmacie.length; i++) {
        marker = new L.marker([planesPharmacie[i][1],planesPharmacie[i][2]], {icon: PharmacieIcon})
            .bindPopup(planesPharmacie[i][0])
            .addTo(map);
    }
    /* END PHARMACIE */
</script>