×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    20

    Coordinates.distance() question

    what formula does the Coordinates.distance() use? i would like to know because i want to convert x,y to latitude,longitude for a webapp..

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Coordinates.distance() question


  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    Re: Coordinates.distance() question

    Code:
     
    public static double distanceBetween(double lat1, double lon1, double lat2, double lon2) 
            {
                try {
                    double lat1Rad = Math.toRadians(lat1);
                    double lon1Rad = Math.toRadians(lon1);
                    double lat2Rad = Math.toRadians(lat2);
                    double lon2Rad = Math.toRadians(lon2);
                    double dlat = lat2Rad - lat1Rad;
                    double dlon = lon2Rad - lon1Rad;
                    double a = Math.sin(dlat / 2.0) * Math.sin(dlat / 2.0) + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.sin(dlon / 2.0) * Math.sin(dlon / 2.0);
                    double c = 2.0 * Float11.asin(Math.min(1.0, Math.sqrt(a)));
                    return 6367000.0 * c; // 6367000 = radius of Earth at 45° of latitude
                }
                catch (Exception e) {
                    return Double.NEGATIVE_INFINITY;
            }
        
         }
    you have to include a float11.java library

    Rocco

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    20

    Re: Coordinates.distance() question

    thanks for the code and the link!!
    another question... how can i convert the coordinates from gps to pixel coordinates?

Similar Threads

  1. Replies: 9
    Last Post: 2010-08-03, 07:03
  2. a question about command and a question about s60
    By t4kesting in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-24, 08:21
  3. Replies: 2
    Last Post: 2004-01-08, 18:36
  4. Sending data using iAcceptedSocket (Urgent question)
    By okegame in forum Bluetooth Technology
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •