×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    37

    Thumbs down How to calculate distance between to geo points in j2me?

    Hi All,

    Below is the code to calculate distance between two geo points.

    public double distance_Haversine(double latVal1,double lonVal1,double latVal2,double lonVal2)
    {
    double dist = 0.0;
    double deltaLat = Math.toRadians(latVal2 - latVal1);
    double deltaLon = Math.toRadians(lonVal2 - lonVal1);
    latVal1 = Math.toRadians(latVal1);
    latVal2 = Math.toRadians(latVal2);
    lonVal1 = Math.toRadians(lonVal1);
    lonVal2 = Math.toRadians(lonVal2);
    double earthRadius = 6371;

    double a = Math.sin(deltaLat/2) * Math.sin(deltaLat/2) +
    Math.cos(latVal1) * Math.cos(latVal2) * Math.sin(deltaLon/2) * Math.sin(deltaLon/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    dist = earthRadius * c;

    return dist;
    }

    it works fine in android but when i tried to use it in core j2me through net Beans it is giving me error like function atan2 is not supported.

    I had imported all the math libraries however my program failed to compile.

    Can some one give me any alternative to calculate distance between two Geo points or any alternative math function to replace atan2??
    Mayur Dharukiya
    WWW.MAYURDHARUKIYA.COM
    J2ME Team Lead at eTechnolabs.com
    Symbian S60 Ambassador
    Nokia Pilot

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to calculate distance between to geo points in j2me?

    You can use JSR 179 for this:

    Refer to http://discussion.forum.nokia.com/fo...d.php?t=197098

    thanks,
    ~Amitabh

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

    Re: How to calculate distance between to geo points in j2me?

    apart from Math functionalities you can use the following IF you're using the JSR179 API :
    - from the JSR179 API you get a Locatio object which contains a Coordinates object
    - the Cooridnates object has a method (forgot the name but you can check the JSR179 documentation) which will give you the disctance between the called coordinates object and a second (passed) coordinates object

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to calculate distance between to geo points in j2me?

    the Cooridnates object has a method (forgot the name but you can check the JSR179 documentation) which will give you the disctance between the called coordinates object and a second (passed) coordinates object
    distance
    public float distance(Coordinates to)Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84. Altitude is neglected from calculations.
    The implementation shall calculate this as exactly as it can. However, it is required that the result is within 0.35% of the correct result.

    javax.microedition.location.Coordinates
    Method name is distance

    Parameters:
    to - the Coordinates of the destination
    Returns:
    the distance to the destination in meters
    Throws:
    java.lang.NullPointerException - if the parameter is null


    thanks,
    ~Amitabh

Similar Threads

  1. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32
  2. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36
  3. J2ME Polish 1.0 RC1!
    By enough in forum Mobile Java General
    Replies: 1
    Last Post: 2004-06-15, 02:53
  4. TinyLine SVG Minute Toolkit: Optimizing SVG for J2ME
    By girow in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2003-05-05, 18:44
  5. TinyLine SVG Minute Toolkit for J2ME: version 1.4 released
    By girow in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-05, 16:25

Posting Permissions

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