Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert meters to latitude longitude from any point

In my project I have to find [latitude, longitude] coordinate(s) from one point in distance of 500 meters (this could be any random coordinate or an array of coordinates around my point). How can I do this?

Note: I need this in order to find multiple paths between points different from shortest one which is returned us via Google Maps Directions Api..So using my method I will define the center of the road from A to B and then find some coordinates below and above that center position and use this as another waypoint to go from A to B - I guess this might help me to find multiple paths...

Any suggestions from GIS professionals?

EDIT: UTM conversion is the most preferable one for such calculations, and I've created UTM Java class if anyone needs..

like image 286
Zaur Guliyev Avatar asked Dec 21 '11 08:12

Zaur Guliyev


2 Answers

This is the code used by google map (SphericalUtil.java)

  // from  SphericalUtil.java
  // compile 'com.google.maps.android:android-maps-utils:0.4.4'
  public static LatLng computeOffset(LatLng from, double distance, double heading) {
    distance /= 6371009.0D;  //earth_radius = 6371009 # in meters
    heading = Math.toRadians(heading);
    double fromLat = Math.toRadians(from.latitude);
    double fromLng = Math.toRadians(from.longitude);
    double cosDistance = Math.cos(distance);
    double sinDistance = Math.sin(distance);
    double sinFromLat = Math.sin(fromLat);
    double cosFromLat = Math.cos(fromLat);
    double sinLat = cosDistance * sinFromLat + sinDistance * cosFromLat * Math.cos(heading);
    double dLng = Math.atan2(sinDistance * cosFromLat * Math.sin(heading), cosDistance - sinFromLat * sinLat);
    return new LatLng(Math.toDegrees(Math.asin(sinLat)), Math.toDegrees(fromLng + dLng));
}

to use it, you just have to enter the centerLatLng, the distance in meters, and the heading in degrees from centerLatLng.

you can change the formula to the language of your preference.

like image 168
Angel Koh Avatar answered Oct 24 '22 09:10

Angel Koh


If I understand your question right you have a known point in Lat/Long and you need calculate the Lat/Long of another point or points 500m away from your starting point.

If this is what you are doing, you have several options most of which involve specialist GIS APIs. However, I'm guesing you're a programmer/mathematician rather than a Geographer so, you may prefer to opt for using the Haversine formula. You can find a discussion on this topic here plus the formula.

One caveat is that the distamce you are working with (500m is quite small) and the Earth is far from being a perfect sphere or even a slightly flattened spheroid. It is locally "lumpy" and that can put your calculation out. If you need more accuracy you will have to account for these imperfections by using an appropriate local Datum (model of the Earth - there are many e.g. see EPSG list) and to do that you will probably need to start using the GIS libraries as the maths gets very detailed otherwise.

like image 44
MappaGnosis Avatar answered Oct 24 '22 10:10

MappaGnosis