Géolocalisation + Google Map

Scipt complet

    1ere partie: Unserialize les information provenant de l'API.
    <?php
      function get_ip() {
      // IP si Internet partagé
      if (isset($_SERVER['HTTP_CLIENT_IP'])) {
      return $_SERVER['HTTP_CLIENT_IP'];
      }
      // IP derrière un proxy
      elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      return $_SERVER['HTTP_X_FORWARDED_FOR'];
      }
      // Sinon: IP normale
      else {
      return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
      }
      }                                                    
    $real = get_ip();
    $url = "http://ip-api.com/json/$real";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $json = curl_exec($ch);
    curl_close($ch);
    
    $tracking = json_decode($json);
                                           
    $realIP = $real;
    $realPays = $tracking->country;
    $realCode = $tracking->countryCode;
    $realRegion = $tracking->regionName;
    $realVille = $tracking->city;
    $realCp = $tracking->zip;                         
    $realLat = $tracking->lat;              
    $realLong = $tracking->lon;
    $realisp = $tracking->isp;
    $realorg = $tracking->org;
    $realas = $tracking->as;                        
    ?>
    
    <b>Affichage Infos:</b><br /> <br />
    Adresse IP: <?php echo $realIP ?>
    <br />
    Pays: <?php echo $realPays ?>
    <br />
    Code Pays: <?php echo $realCode ?>
    <br />
    Région: <?php echo $realRegion ?>
    <br />
    Ville: <?php echo $realVille ?>
    <br />
    Code Postal: <?php echo $realCp ?>
    <br />
    Latitude: <?php echo $realLat ?>
    <br />
    ISP Nom <?php echo $realisp ?>
    <br />
    AS number: <?php echo $realas ?>
    <br /> <br />
    
    2ere partie: Maintenant, pour aller plus loin, nous affichons Google Map.         
      
    <style>
    #map {height: 400px; width: 100%;}#map-1-3 {height: 200px;width: 100%;}
    /* Le script ne fonctionnera pas sans le css -----  Ici nous allons utiliser l' id map */
    </style>         
  
    <?php
    $apiKey = "AIzxxxxxxxxxxxxx";
    // Votre clé API Google
    ?>
      <div id="map"></div>         
  
   <script type="text/javascript">
      function initMap() {
      var <?php echo $realVille; ?> = {lat: <?php echo $realLat; ?>, lng: <?php echo $realLong; ?>};
      var map = new google.maps.Map(document.getElementById('map'), {
      scaleControl: true,
      center: <?php echo $realVille; ?>,
      zoom: 13
      });
      var infowindow = new google.maps.InfoWindow;
      infowindow.setContent('<b><?php echo $realVille; ?></b>');
      var marker = new google.maps.Marker({map: map, position: <?php echo $realVille; ?>});
      marker.addListener('click', function() {
      infowindow.open(map, marker);
      });
      }
      </script>         
    
  <script async defer
      src="https://maps.googleapis.com/maps/api/js?key=<?php echo $apiKey; ?>&language=fr®ion=<?php echo $realCode; ?>&callback=initMap">
      </script>
    
      Et voilà ... Pour aller enconre plus loin, rien n'empêche d'enregistrer en base de donnée
      les informations récupérées comme $realIP, $realPays etc ...