0

I want to find the point which is some X kms from the current point say A, Example

if I know the latitude and longitude of center point How can I get the latitude, longitude of four points at circumference.... I am searching SO for quite long but not able to get the solution in JavaScript or in Java... distance In my case will be in few kms so cant consider earth as flat surface so plz dont suggest such solution...

Thanks

Amit
  • 13,134
  • 17
  • 77
  • 148
  • is it just four random points on the circle you want? – Atheist Sep 28 '11 at 11:39
  • no points where in above example lines touch the circumference.... at 0,90,180,270 degrees – Amit Sep 28 '11 at 11:43
  • a few points for you to consider - All points on the circle will be the required distance away from the center , not just the 4.-Number of kilometers per degree change is latitude/longitude is not a constant -Once you determine what factor you should use to convert kilometers into degree changes in latitude/longitude , this should be easy , if you also know the eqn of a circle, given it's radius and center co-ordinates. – amal Sep 28 '11 at 11:43
  • 1
    And yes , If you do want to work out the longitude to km relation based on center co-ordinates given , you can find the necessary equations at http://en.wikipedia.org/wiki/Longitude – amal Sep 28 '11 at 11:46
  • @amal... ofcourse I know the properties of a circle.... I want to know what is maximum change in latitude and longitude values in all the directions from a given point(A) and a given distance (X kms) ... – Amit Sep 28 '11 at 11:48
  • @nnnnnn : U got m point... but in some answers I visited, answers were in specific to PHP or C# hard to customize for my use... thats I why I tagged this question with Java and javaScript . . . . . – Amit Sep 28 '11 at 13:23

2 Answers2

6

Take a look at this page which explains in great detail the spherical model for distance calculation with JavaScript examples:

Given a start point, initial bearing, and distance, this will calculate the destination point and final bearing travelling along a (shortest distance) great circle arc.

JavaScript:

var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
                      Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                             Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
  • thanks for quick reply @Andrey... I am trying to follow this titurial for quite a few hours... the place where I am confused is just one line above from snippet you mentioned in ur answer... `d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius` ..I have distance in Kms how I can change that to specified format.... help!!! – Amit Sep 28 '11 at 11:55
  • have you looked in http://www.movable-type.co.uk/scripts/latlon.js? LatLon.prototype.destinationPoint = function(brng, dist)? dist = dist/this._radius; ? – Andrey Adamovich Sep 28 '11 at 12:20
2

I was crushing the code above Until I did not realized that both lat and lon are the radian Value! You have to convert them back to the degrees, and you will see real values.

Here is the code

public class cal
{         
     public static void main(String []args){
         double R = 6371.0;
         double d = 0.100;
         double lat1 = 42.873, lon1 = 74.568;
         double Radlat1 = Math.toRadians(42.873);
         double Radlon1 = Math.toRadians(74.568);
         double brng = Math.toRadians(225);
         double lat2,lon2;

        System.out.println("Hello World");
        //lat2 = Math.sin();

        lat2 = Math.asin(Math.sin(Radlat1)*Math.cos(d/R) + 
                      Math.cos(Radlat1)*Math.sin(d/R)*Math.cos(brng));



         System.out.println("Lat2degree"+"="+Math.toDegrees(lat2)+"\n"+"Lat2="+lat2);

        double NewRadLat2 = Math.toRadians(Math.toDegrees(lat2));


        lon2 = Radlon1+Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(Radlat1), 
                             Math.cos(d/R)-Math.sin(Radlat1)*Math.sin(lat2));

        System.out.println("Lon2"+"="+Math.toDegrees(lon2));

     }
}
Didier Aupest
  • 3,227
  • 2
  • 23
  • 35
Baimyrza Shamyr
  • 449
  • 1
  • 6
  • 17