How can I pass more than one point to google maps in that while?

Asked

Viewed 46 times

0

I wanted to mark all the points where the approximate distance is less than 25 km, but it doesn’t even show the first point that is the nearest (4km), it shows the last one (18km). Follow what comes from my bank:

Array ( [0] => -22.356472 [latitude] => -22.356472 [1] => -47.361216 [longitude] => -47.361216 ) 0    
Array ( [0] => -23.479701 [latitude] => -23.479701 [1] => -47.447751 [longitude] => -47.447751 ) 125    
Array ( [0] => -23.479701 [latitude] => -23.479701 [1] => -47.447751 [longitude] => -47.447751 ) 125    
Array ( [0] => -23.479701 [latitude] => -23.479701 [1] => -47.447751 [longitude] => -47.447751 ) Distância 125    
Array ( [0] => -22.384003 [latitude] => -22.384003 [1] => -47.378910 [longitude] => -47.378910 ) Distância 4    
Array ( [0] => -22.906058 [latitude] => -22.906058 [1] => -47.063822 [longitude] => -47.063822 ) Distância 68    
Array ( [0] => -22.483987 [latitude] => -22.483987 [1] => -47.449943 [longitude] => -47.449943 ) Distância 17    
Array ( [0] => -22.368794 [latitude] => -22.368794 [1] => -47.533523 [longitude] => -47.533523 ) Distância 18

.php:

<?php
    include('dcclinicas/include/conexao.php');
    $idUsuario = '7';

    $lat = $link->query("SELECT latitude FROM usuarios WHERE id ='$idUsuario'")->fetch_assoc();
    $long = $link->query("SELECT longitude FROM usuarios WHERE id = '$idUsuario'")->fetch_assoc();          

    $dados = $link->query("SELECT latitude, longitude FROM usuarios");

    while($cont = mysqli_fetch_array($dados)){
        $distancia = distanciaPontos($lat['latitude'],$long['longitude'], $cont['latitude'], $cont['longitude']);
        echo "<br>";

        if($distancia <= '25'){
              $latDestino = $cont['latitude'];
              $longDestino = $cont['longitude'];    

              echo '<script type = "text/javascript">  
                      function loadMap() {
                        if (GBrowserIsCompatible()) {
                          var map = new GMap2(document.getElementById("map"));
                          map.setCenter(new GLatLng('.$lat['latitude'].', '.$long['longitude'].'), 6);
                          var markerAtual = new GMarker(new GLatLng('.$lat['latitude'].','.$long['longitude'].'));
                          var marker = new GMarker(new GLatLng('.$latDestino.', '.$longDestino.'));

                          map.addOverlay(markerAtual);
                          map.addOverlay(marker);
                        }
                      }
                    </script>';
        }
        $cont++;
        print_r($cont);
        print_r(" ".$distancia);

    }
  • Remembering that I want to show all points that are less than 25 km. Thank you ^-^

1 answer

0

You are generating multiple maps with this code, all of them overwrite the last, so you are only returning the last point.

Your loop should be after var map = new GMap2(document.getElementById("map")); if not it creates another map.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.