Calculate speed Km/h latitude and longitude

Asked

Viewed 642 times

-2

People if every 5 minutes I cover 10 kilometer how many miles per hour I am traveling ?

If anyone can help there thank you follow the code:

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;
}

echo distancia(-4.077559, -63.127536, -4.063721, -63.038268) . " Km<br />";
  • 1

    If 5 minutes is to 10km how many kilometres is to 60 minutes solves the expression that will get the result: 5x = 60 * 10; 5x = 600; x = 600 / 5 = 120 KM ...

  • V is speed, S is space, t is time. General formula for uniform motion V=S/t replacing gets V=10/5 therefore V= 2Km/min calculating the space travelled in one hour S=v*t therefore S=2*60=120km

  • From "head" an hour has how many 5minutes? answer: 12, so it is 12*10=120

  • Your question is not clear enough taking into account the code presented!

1 answer

0

It became half vacant where this average speed will be used. But as was margin of interpretation, I imagined the following situation:

Based on the statement

Every 5 minutes I go 10 kilometers per hour

I created a function that takes a time in minutes and a distance in kilometers and returns the average speed. And then you would "want" to check how long, going at calculated speed, would it take to travel the distance returned by the function distancia().

Plus I include the solution for that other one of yours question, which is basically create variables for latitudes and longitudes. If it does not fit your needs let us know in 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 />";
  • Buddy @Juve_v Perfect your answer just can’t put the variable appears this Warning: deg2rad() expects Parameter 1 to be double, Object Given

  • Type like $latitude_origin = $latitude_um;

  • It depends on how you boot $latitude_um, probably is null or something other than a number.

Browser other questions tagged

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