echo "<br><br>======================================<br><br>"; //===============================================================// //ENDEREÇO DA COOPERATIVA NO FORMATO DO BANCO $cooEndereco = "Rua Peixoto Gomide"; $cooNumero = "296"; $cooCidade = "São Paulo"; $cooEstado = "SP"; $cooCep = "01.409-000"; //CONVERTE ENDEREÇO PRA STRING ÚNICA $cooEnderecoFormatado = $ApiMaps->formatAddress($cooEndereco, $cooNumero, "{$cooCidade}", $cooEstado, $cooCep); echo "Endereço da cooperativa formatado: <br>" . $cooEnderecoFormatado . "<br><br>"; //CHAMA FUNÇÃO QUE RETORNA LATITUDE E LONGITUDE $cooLatLng = $ApiMaps->getLatLng($cooEnderecoFormatado); //ACESSA ARRAY COM LATITUDE E LONGITUDE echo "Latitude: " . $cooLatLng['lat']; echo "<br>"; echo "Longitude: " . $cooLatLng['lng']; echo "<br><br>======================================<br><br>"; //===============================================================// //CONVERTE EM COORDENADAS OS DOIS ENDEREÇOS $coordenadasEndereco = $LatLng['lat'] . "," . $LatLng['lng']; $coordenadasCooEndereco = $cooLatLng['lat'] . "," . $cooLatLng['lng']; //CALCULA DISTANCIA E TEMPO ENTRE OS DOIS ENDEREÇOS $distanceEnderecos = $ApiMaps->getDistance($coordenadasEndereco, $coordenadasCooEndereco); //ACESSA ARRAY COM DISTÊNCIA E DURAÇÃO echo "Distância: " . $distanceEnderecos['distanceText'] . " (" . $distanceEnderecos['distanceValue'] . ")"; echo "<br>"; echo "Duração: " . $distanceEnderecos['durationText'] . " (" . $distanceEnderecos['durationValue'] . ")"; ?> </body> </html>
$distances = ""; //LOOP ATÉ ENCONTRAR COOPERATIVA while (true) { //LOOP NOS MODIFICADORES A PARTIR DO MAIS PERTO foreach ($modifiers as $modifier) { //WHERE EM COORDENADAS COM BASE NO MODIFICADOR $search = " AND (coo_lat >= '" . ($LatLng['lat'] - $modifier) . "' AND coo_lat <= '" . ($LatLng['lat'] + $modifier) . "') AND (coo_lng >= '" . ($LatLng['lng'] - $modifier) . "' AND coo_lng <= '" . ($LatLng['lng'] + $modifier) . "')"; //CARREGA COOPERATIVAS $oCooperativas = $Cooperativa->carregarCooperativas(" AND coo_ativo='1'" . $search, "coo_nome ASC", ""); //LOOP EM TODAS COOPERATIVAS NESSE RAIO if ($oCooperativas) { foreach ($oCooperativas as $coo) { //COORDENADAS DO ENDEREÇO DA COOPERATIVAS $cooEndereco = number_format($coo->getLatitude(), 6) . "," . number_format($coo->getLongitude(), 6); //CHAMA FUNÇÃO QUE CALCULA DISTÂNCIA E TEMPO $distance = $ApiMaps->getDistance($cooEndereco, $usuEndereco); if ($distance) { //POPULA ARRAY COM TEMPO E ID DE CADA COOPERATIVA $distances[$coo->getCooperativaID()] = $distance['durationValue']; } } } //SE ENCONTRAR COOPERATIVAS SAIR DO LOOP if (!empty($distances)) { break 2; } } } //RETORNA A POSIÇÃO DA MENOR DISTÂNCIA DO ARRAY $betterDistance = array_search(min($distances), $distances); // ====================================================== //