Question

I do this on Android with Google Maps.

I have an arraylist of GeoPoint's. GeoPoint API is here.

List<GeoPoint> geoPoints;

Now I want to check the frequency of each GeoPoint. If there is some intersect (because two of them are equal) I want to print out a debug log.

Collections.frequency(geoPoints, geoPoints.get(i)); doesn't return me the correct result, it doesn't check if two points intersect...

Was it helpful?

Solution

Most likely, while drawing with a finger on the map you will never have two geopoints on exactly same location.

The simplest approach you can use is to test the distance from one geopoint projection coordinates to the other, and if this distance is less then a thresould value it would be consider the same point.

Example

projection.toPixels(geoArrList.get(i), pointToTest);

Point p1 = new Point();
for(int i=0; i<geoArrList.size(); i++){
    projection.toPixels(geoArrList.get(i), p1);
    int squareDistance = ((pointToTest.x - p1.x) * (pointToTest.x - p1.x) +
        (pointToTest.y - p1.y) * (pointToTest.y - p1.y));
    if(squareDistance  < THRESOULD){
        //same point
    }
}

Regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top