Stagleton
Stagleton

Reputation: 1060

Validating/Entering GPS coordinates

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?

Upvotes: 1

Views: 1699

Answers (1)

NickT
NickT

Reputation: 23873

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.

Upvotes: 2

Related Questions