Offset LatLng for a few meters in Android

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?

+5
source share
2 answers

You can use the computeOffset method from the Google API Utility of the Android API ( https://developers.google.com/maps/documentation/android-api/utility/ ):

public static LatLng computeOffset (LatLng from, double distance, double header)

Returns LatLng as a result of moving the distance from the origin in the specified header (expressed in degrees clockwise from the north).

Parameters:

  • from - LatLng from which to start.
  • distance - the distance to travel.
  • heading - heading in degrees clockwise from the north.

In your case (the distance parameter is measured in meters):

 LatLng east = SphericalUtil.computeOffset(midpoint, 500, 90); // Shift 500 meters to the east LatLng west = SphericalUtil.computeOffset(midpoint, 500, 270); // Shift 500 meters to the west 
+10
source

It is not possible to get the exact offset in meters from latitude and longitude. This suggests that the Earth is a perfect and smooth sphere that is not true.

If you want to reduce your error, you must adjust the number of kilometers per degree according to your latitude. The answer you associate has an estimate of 111 km per degree, but it depends on your latitude (especially in the direction of longitude). See the table:

 LatLat≃ 1°Lon≃ 0° 110.574 km 111.320 km 15° 110.649 km 107.550 km 30° 110.852 km 96.486 km 45° 111.132 km 78.847 km 60° 111.412 km 55.800 km 75° 111.618 km 28.902 km 90° 111.694 km 0.000 km 

Link: wikipedia: P

Hope this helps!

+2
source

All Articles