It has become somewhat vague where this medium speed is going to be used. But as there was room for interpretation, I imagined the following situation:
Based on the statement
Every 5 minutes I travel 10 kilometers how many kilometers per hour I am traveling
I created a function that gets a time in minutes and a distance in kilometers and returns to average speed. And then you "would" want to check how long, going at the calculated speed, would be required to traverse the distance returned by the distancia()
function.
In addition, I include the solution for this your other question , which is basically to create variables for latitudes and longitudes. If it does not fit your needs tell us the comments.
<?php
$latitude_origem = -4.077559;
$longitude_origem = -63.127536;
$latitude_destino = -4.063721;
$longitude_destino = -63.038268;
function distancia($lat1, $lon1, $lat2, $lon2) {
$lat1 = deg2rad($lat1);
$lat2 = deg2rad($lat2);
$lon1 = deg2rad($lon1);
$lon2 = deg2rad($lon2);
$dist = (6371 * acos( cos( $lat1 ) * cos( $lat2 ) * cos( $lon2 - $lon1 ) + sin( $lat1 ) * sin($lat2) ) );
$dist = number_format($dist, 2, '.', '');
return $dist;
}
/**
@param $tempo um numero, representando os minutos
@param $distancia um double representando a distancia percorrida em $tempo
(distancia em quilometros)
@return double velocidade em quilometros por hora (Km/h)
*/
function converterParaKmHora($tempo, $distancia){
//60 representa a quantidade de minutos em uma hora
$velocidade_km_hora = ($distancia * 60) / $tempo;
return $velocidade_km_hora;
}
$velocidade_media = converterParaKmHora(5, 10);
$distancia_entre_pontos = distancia($latitude_origem, $longitude_origem , $latitude_destino, $longitude_destino);
echo $distancia_entre_pontos . " Km<br />";
echo $velocidade_media . " Km/h<br />";
echo ($distancia_entre_pontos/$velocidade_media) . " horas para completar o percurso<br />";