Theme images by Storman. Powered by Blogger.

21 July 2016

How to calculate distance on google maps with php?

How to calculate distance on google from latitude and longitude. we need to get first point of latitude and longitude and point to end of our destination:

like from A-------------------------------------------> B (How many km?)



Here is the following code to solve this problem:

 
<?php

$lat1 = '11.570587';
    $lat2 = '11.570597';
    $lon1 = '104.898414';
    $lon2 = '104.898468';

    $dist   = acos(sin(deg2rad($lat1))
              * sin(deg2rad($lat2))
              + cos(deg2rad($lat1))
              * cos(deg2rad($lat2))
              * cos(deg2rad($lon1 - $lon2)));

    $dist   = rad2deg($dist);
    $miles  = (float) $dist * 69;

    // To get kilometers, multiply miles by 1.61
    $km     = (float) $miles * 1.61;

    // This is all displaying functionality
    $test  = sprintf("%0.2f",$miles).' miles' ;
    $display = sprintf("%0.2f",$km).' kilometers' ;

    echo $display ;
?>

By SharingBlog.xyz


0 on: "How to calculate distance on google maps with php? "