[GIS] Converting from an x-y coordinate system to latitude/longitude

coordinate systemgoogle mapstrilateration

I'm building an indoor wifi-based tracking system that can calculate the position of a device in meters relative to the sensors distributed throughout the building. So far I've gotten to the point where I have the ability to sense the device and trilaterate its position on an arbitrary x-y grid (in meters) where the sensor locations are known, but now I need to output that to Google Maps for display. I'm stuck trying to figure out how to convert this system to latitude and longitude, and be accurate to within a meter. I've seen some estimations people have used for such applications, but they're plotting on a much larger scale so an error of 10m or so is acceptable. In my case, 10m would make the data completely unusable.

Is there an easy way to make this conversion? I can find the lat/lon of the sensors, but I don't know where to go from there. My equations are based on a point-coordinate system, so I can't use a vector system or other method without redesigning everything.

Best Answer

To a high relative accuracy, in this application--where the region to be mapped will not extend more than a few hundred meters and it is not near either pole--you can treat lat-lon as a Cartesian coordinate system that uses two different linear units of measure.

Each degree of latitude will be approximately 111300 meters (and a more accurate value, which may differ from this by up to a few hundred meters, can be found once and for all by consulting tables or through a preliminary calculation). Each degree of longitude will be approximately 111300 * cos(latitude) meters (with the same possibility of making it a little more accurate with a little more preliminary work). For the latitude in the equation use the latitude of the middle of the building. The errors will be much smaller than one meter.

For example, suppose you locate an object 10 meters west and 20 meters north of a sensor at (lat, lon) = (45.000100, 6.500000) and the building's center is at latitude 45 degrees. Since cos(45) = 0.7071068, each degree of longitude is worth 111300 * 0.7071068 = 78701 meters. Therefore the object is displaced 10/78701 = 0.0001271 degrees west (which is the negative direction) and 20/111300 = 0.0001797 degrees north. This would locate it at (lat, lon) = (45.000100, 6.500000) + (0.000180, -0.000127) = (45.000280, 6.499873).

Assuming the sensor locations are perfectly accurate, note that even a 5% error in these particular calculations would still place the final coordinates within 5%*20 = 1 meter of their correct locations. That's why there's no need to be finicky about accuracy in the conversion from meters to degrees: one part in a thousand would be more than good enough for any building.

(For advice on precision in these coordinates please see Measuring accuracy of latitude and longitude?.)