2

Okay, here's my problem. The system I'm working with uses objects called Areas to represent a 920x920 metre area on a map. The only reference given for the Area, however, is the latitude and longitude for the top-left corner of the grid square.

What I need to do is work out whether the user's current GPS location falls within a specific area, so I'm writing a function that checks if this is the case, and if so returns data from that area object.

Where I'm struggling is actually working out the best way to do the location checking, when all I have to go on is the user's exact lat/long and a known lat/long for the top left of the grid square...what would be the best way to approach this problem?

Many thanks for any help.

Sam
  • 153
  • 2
  • 11
  • There seems to be a problem with the way you're trying to set this up. If you only have square areas to work with, I don't think you can uniquely tile the world without having any overlapping regions (think about what happens near the poles). – templatetypedef Jan 15 '11 at 20:39
  • possible duplicate of http://stackoverflow.com/questions/4287780/detecting-whether-a-gps-coordinate-falls-within-a-polygon-on-a-map –  Jan 15 '11 at 20:41
  • @templatetypedef - The system only covers a smallish city, so that's not really a concern - in any case, I'm restricted to this way of doing things as I'm building on a (not very well documented) existing system... – Sam Jan 15 '11 at 20:45
  • I'm guessing from your spelling of 'metres', that you are here in the UK? If so the Ordnance Survey website has some really useful and accurate coordinate system transformation algorithms. It's easier here than in the USA, as we only have one projection zone, unlike the UTM grid which requires many to minimise map distortions. Don't go too crazy on accuracy if those 920x920m zones are only approximate, or are based on a spherical projection rather than an ellipsoidal one. Note that all GPS systems use the WGS84 ellipsoid rather than the 1936 Airy. – NickT Jan 15 '11 at 21:41
  • Check: http://www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/guide6.html – NickT Jan 15 '11 at 21:44

1 Answers1

3

Step #1: Port these calculations (or the equivalent) to Java and use them to determine how many degrees of latitude or longitude 920 meters is given your coordinates

Step #2: Use the values from Step #1 to determine the latitude/longitude coordinates of the lower-right corner of your square

Step #3: See if the user's longitude is between the left and right values, and if the user's latitude is between the top and bottom values

Just be careful as you get to the key inflection points (0 degrees latitude, +/-180 degrees latitude, etc.).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491