I wanted to mark all points where the approximate distance is less than 25 km, but it does not even show the first point that is the closest (4km), it shows the last point (18km). Here's 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);
}