metteo / javageomodel

Automatically exported from code.google.com/p/javageomodel
0 stars 0 forks source link

Cannot find GeoPoint that exists in DB #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Perform GeocellManager.proximityFetch(..) where center point is equal to 
a point stored in db.  

What is the expected output? What do you see instead?
Expected : Stored GeoLocated item should be found. 
Experienced: Point is not found.
What version of the product are you using? On what operating system?
0.3

Please provide any additional information below.

It seems that the issue is caused by double precision calculations.  
GeocellUtils.distance(...) uses  Math.acos(arg) method do do some 
calculations. In some cases arg > 1 (i.e 1.0000000002), so acos cannot be 
calculated and the method returns NaN. My solution is very simple, but 
should work:

public static double distance(Point p1, Point p2) {
        double p1lat = Math.toRadians(p1.getLat());
        double p1lon = Math.toRadians(p1.getLon());
        double p2lat = Math.toRadians(p2.getLat());
        double p2lon = Math.toRadians(p2.getLon());
        return RADIUS * Math.acos(makeDoubleInRange(Math.sin(p1lat) * 
Math.sin(p2lat) +
                Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(p2lon - 
p1lon)));
    }

    public static double makeDoubleInRange(double d){
        double result = d;
        if(d>1){
            result =1;
        }
        else if(d<-1){
            result = -1;
        }

        return result;

    }

Original issue reported on code.google.com by m.szerl...@gmail.com on 26 May 2010 at 12:25

GoogleCodeExporter commented 9 years ago

Original comment by alexandr...@gmail.com on 10 Nov 2010 at 7:27