12

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..

Zaur Guliyev
  • 4,254
  • 7
  • 28
  • 44

2 Answers2

6

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
MappaGnosis
  • 1,179
  • 1
  • 11
  • 25
  • Looks like a good method.. For know I'm trying the same thing using UTM to [lat, long] and vice versa calculations method in order to find appropriate coordinates and lat,long during calculations. I think this method also is the same with yours but only formulas are different, but I've read that UTM formulas can convert locations exactly in centimeters... Btw thanks a lot for your response! – Zaur Guliyev Dec 21 '11 at 14:19
  • 2
    UTM already accounts for local deformation of the Earth's surface by dividing the Earth into large number of zones, each with its own datum. This is why it is much more accurate than, say, WGS which uses a single projection for the whole of the Earth. If you need tools to convert to cartesian coordinates - calculate your points and convert back to Lat/Long without worrying about the maths, check out GDAL/OGR (and especially OSR - which is the spacial referencing API) – MappaGnosis Dec 21 '11 at 14:33
3

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.

Angel Koh
  • 12,479
  • 7
  • 64
  • 91