Hi,

I have a task where, when I select a city, I should also be shown with other nearest cities to the selected one. I have been given with a list of latitude and longitude values, using which I should make some calculations and find out the nearest cities. Does anyone have any idea of how to do those calculations?

Thanks,
Bindu.

    Search the forums. I guess two keywords you could use are "latitude" and "longitude".

      What you're looking for is called "great circle calculation."

      A simple Google search turns up this link:

      http://greatcircle.locallink.net/

      and this code:

      Function greatcircle_fun($long1, $long2, $lat1, $lat2)
      {
        $distance= 1.15077 * 60.0 * rad2deg(
        acos(sin(deg2rad($lat1))*sin(deg2rad($lat2))+
        cos(deg2rad($lat1))*cos(deg2rad($lat2))*
        cos(deg2rad($long2) - deg2rad($long1)))
        );
      
        return $distance;
      } 
      

        Do you have any idea, if the output that is $distance is in KM or Miles or Nautical Miles. I am not able to make out. What is the general format of the latitude and longitude values?

        Thanks,
        Bindu.

        Originally posted by yelvington
        What you're looking for is called "great circle calculation."

        A simple Google search turns up this link:

        http://greatcircle.locallink.net/

        and this code:

        Function greatcircle_fun($long1, $long2, $lat1, $lat2)
        {
          $distance= 1.15077 * 60.0 * rad2deg(
          acos(sin(deg2rad($lat1))*sin(deg2rad($lat2))+
          cos(deg2rad($lat1))*cos(deg2rad($lat2))*
          cos(deg2rad($long2) - deg2rad($long1)))
          );
        
          return $distance;
        } 
        

        [/B]

          ....and this is why I don't just shovel finished code out to people who haven't worked for it.

            Thanks to all for the help, especially to Mr. Yelvington. The script works fine.

              Hey, I found another code snippet from weberdev code examples.

              http://www.weberdev.com/get_example.php3?count=3548

              This is a much better code I believe.

              Though I am not aware of mathematical calculations, I am still putting all my efforts to get the best result. I wish people out here appreciate for that.

                Write a Reply...