开发者

How to find the latitude and longitude of a point from a given point, given the distance between the two?

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

How to find the latitude and longitude of a point from a given point, given the distance between the two?

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


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));


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));

     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜