0

Given an existing point in lat/long, distance(inches) and bearing (in degrees converted to radians), I'm trying to calculate the new lat/long. But the resulting is some times inaccurate because I'm trying to measure a small area for the new lat/long. Currently, I'm trying to get the next foot lat/long but some times it has a 1-inch error. I used the following algorithm for this implementation. Referred this thread for the algorithm Get lat/long given current point, distance and bearing.

public LatLng calculateLatLangFromDistance(double brng, double distance, LatLng latLng){

    double lat1 = Math.toRadians(latLng.getLatitude());
    double long1 = Math.toRadians(latLng.getLongitude());
    double br = Math.toRadians(brng);


   double lat2 = Math.asin(Math.sin(lat1)*Math.cos(distance/r) +
           Math.cos(lat1)* Math.sin(distance/r)* Math.cos(br));

   double long2 = long1 + Math.atan2(Math.sin(br)*Math.sin(distance/r)*Math.cos(lat1),
           Math.cos(distance/r)-Math.sin(lat1)*Math.sin(lat2));

    lat2 = Math.toDegrees(lat2);
    long2 = Math.toDegrees(long2);

   LatLng latLng1 = new LatLng();
   latLng1.setLongitude(long2);
   latLng1.setLatitude(lat2);

   return latLng1;
}

r is defined as 250826771.6535433 // //Radius of the Earth from inches

I'm using the above implementation to generate a 1-foot grid to mapbox map layer but resulting grid's some lines are 1-inch inaccurate. Is there any way to improve this implementation for better results or is there another way to get accurate lat/long for this?enter image description here

this is the generated grid and I did a line drawing to get the idea about line length of the some lines in the grid.

pixylife
  • 463
  • 4
  • 12
  • Are there still people in this world that calculate in inches? – blackapps Jan 10 '20 at 08:28
  • You should give an exact example of a calculation. Give the three input values. Then tell wich new point you calculated. And tell what you expected it to be. It is unclear why you use a grid at all. – blackapps Jan 10 '20 at 08:32
  • @blackapps yes,in our country some clients calculate the distance in inches ..anyway thanks for the reply I managed to reduce the error – pixylife Jan 15 '20 at 09:52

1 Answers1

1

You can use the spherical geometry utilities of the Google Maps SDK for Android utility library.

The specific method that you can use will be the computeOffset method. You can see it when you search the SphericalUtil in this link.

ComputeOffset returns the LatLng resulting from moving a distance from an origin in the specified heading (expressed in degrees clockwise from north). Here are the parameters that you need to specify:

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

To use this, add the utility library to your dependencies:

implementation 'com.google.maps.android:android-maps-utils:0.5'

This is the sample of a line of code that I use:

LatLng newCoordinates = SphericalUtil.computeOffset(new LatLng(-25.363, 131.044),30000, 90);

Hope this helps!

Pagemag
  • 2,779
  • 1
  • 7
  • 17