1
votes

In this app I am trying to have a user enter GPS coordinates and then a range to search, so enter: latitude, longitude, and distance in km. How do I validate GPS coordinates?

should I just have some method that checks if latitude is between -90 to 90 and if longitude is between -180 and 180 or is there a better way?

For users will just enter coordinates into an EditText window. There is probably a much better way to do this...any references that I should be reading?

1

1 Answers

2
votes

I'd test for the latitude being between -80 and +80, as the constructor of a GeoPoint 'clamps' it to +-80. I.e if you pass +85 in, then it gets changed to +80 without warning.

In fact it does this for totally illegal values too, so rather than throwing an exception for +185, it just changes it to +80. Longitudes get clamped to +- 180.