I have a LatLng object and I want to move it 500 meters east. I could not find a built-in method for this. I saw https://gis.stackexchange.com/a/2964 , but my results are too inaccurate (about 15%) to use them practically. How can I make the exact shift in meters?
Note: I am NOT looking for a Google Maps camera transfer, I know how to do it.
I tried:
static final double KILOMETERS_PER_DEGREE = 111.111; static LatLng offsetLongitude(LatLng initialCoords, float horizontalOffsetInMeters){ double degreeOffset = 1.0 / KILOMETERS_PER_DEGREE * horizontalOffsetInMeters / 1000.0; double longitudeOffset = Math.cos(initialCoords.latitude * Math.PI / 180.0) * degreeOffset; return new LatLng(initialCoords.latitude, initialCoords.longitude + longitudeOffset); } public static LatLngBounds boundsForSpanWidth(LatLng midpoint, float targetSpanWidth){ LatLng east = offsetLongitude(midpoint, -targetSpanWidth); LatLng west = offsetLongitude(midpoint, targetSpanWidth); LatLngBounds newBounds = new LatLngBounds(west, east); return newBounds; }
However, when I call it a point (not close to the poles or anything) with a target range of 5000 meters, I get two points that are at a distance of 6170 meters from each other. Why?
source share