Enhance map info with script

Discussion in 'Google API' started by seedybee68, Feb 20, 2008.

  1. #1
    Since you have a map you probably have x and y coordinate data somewhere in a database.

    Did you know it is really easy to add 'distances between' info on your website by running the following short function

    function haversine ($l1, $o1, $l2, $o2)
    {
    $l1 = deg2rad ($l1);
    $sinl1 = sin ($l1);
    $l2 = deg2rad ($l2);
    $o1 = deg2rad ($o1);
    $o2 = deg2rad ($o2);

    return (7926 - 26 * $sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin ($l2) * $sinl1) - cos ($l1) * cos ($l2) * cos ($o2 - $o1)))));

    }

    to get the result just put the following line of code on your page

    <?php printf ("%01.2f", haversine (51.482692,-0.607431,51.521656,-0.720487)) ?>

    Replace the four variables in the line abouve with the x and y coordinates of the start and end locations
    (I used printf to limit decimal places in the result)

    I hope you find this useful.

    Cheers

    Chris

    Chris:)
     
    seedybee68, Feb 20, 2008 IP