0

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...

kameny
  • 2,372
  • 4
  • 30
  • 40
krackmoe
  • 1,743
  • 7
  • 29
  • 53
  • what do you meen by intersect? – Luis Nov 25 '12 at 13:48
  • when i got 2 geo points with same x and y coordinates it means that two lines intersect each other – krackmoe Nov 25 '12 at 13:52
  • 1
    you are getting it all wrong. `GeoPoint` don't have x,y coordinate, they have Latitude and Longitude. They do not represent lines, they represent points, and points don't intersect. They are the same or they are different. You definitly need to re-think your question ... – Luis Nov 25 '12 at 14:17
  • Sure its about Latitude and Longitude... But.. if i draw a line on google maps with my finger, and at some point this line crosses itself, 2 GeoPoints should have the same Lat and Lon right? And this is what i want to know... How i can compare these objects? – krackmoe Nov 25 '12 at 16:49
  • ok. Now I understood what you want. I'll post an answer for it. – Luis Nov 25 '12 at 16:53

1 Answers1

1

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.

Luis
  • 11,978
  • 3
  • 27
  • 35
  • But if the line intersects itself they must have the same GeoPoint. Why is this thought wrong? I drew you something: http://666kb.com/i/c9a6n21ouo5yru2x3.gif So.. why do they not have the same GeoPoint please? :) – krackmoe Nov 25 '12 at 17:10
  • 1
    Because they are not points. They are small interconnected line segments, which look like points. In the code above, if you set `THRESOULD` to 0, it will check form exactly the same point. Try it and you will see that most likely tou will not get an exact match. – Luis Nov 25 '12 at 17:59
  • You can also check for intersecting line segments, but it will requires much more math. – Luis Nov 25 '12 at 18:00
  • Could you please tell me, the squareDistance is it km? meters? miles? – krackmoe Nov 25 '12 at 19:57
  • It's the square of distance in pixels. First geopoint is converted to position (x,y) in screnn pixels and then the distance in pixels to the other point (x,y) is calculated. So, 1 meens 1 pixels distance, 4 meens 2 pixels distance, 9 meens 3 pixels distance ... – Luis Nov 25 '12 at 21:40
  • sometimes it works.. sometimes it doesnt.. :/ maybe its because of the zoomlevel and the not exact line i draw? maybe draw something by hand isnt the best way.. i dont know? – krackmoe Nov 26 '12 at 17:21