最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - find latitude and longitude using distance - Stack Overflow

programmeradmin2浏览0评论

I want to find Latitude, for example

Point A = (18.5204303,73.8567437)
Point B = (x,73.8567437)
Distance =20KM(Kilometers)

I need to find the latitude(x) of Point B, that is 20 KM from point A.Longitude should be same. Help me Thanks in advance

I want to find Latitude, for example

Point A = (18.5204303,73.8567437)
Point B = (x,73.8567437)
Distance =20KM(Kilometers)

I need to find the latitude(x) of Point B, that is 20 KM from point A.Longitude should be same. Help me Thanks in advance

Share Improve this question edited Jan 15, 2012 at 10:33 RameshVel 65.9k32 gold badges172 silver badges213 bronze badges asked Jan 15, 2012 at 9:45 NishuNishu 993 silver badges12 bronze badges 10
  • 1 Don't you need an angle as well? Otherwise there is an infinite number of B = (x, y) points matching your criteria - on a circle with 20km radius and centre in A... – Tomasz Nurkiewicz Commented Jan 15, 2012 at 9:50
  • Yes,i need Angular radius, But i don't know how to find it. – Nishu Commented Jan 15, 2012 at 9:53
  • 2 so you have a single equation with two unknowns - math is against you ;-). You need to know both: radius and angle to be able to find exactly one B. – Tomasz Nurkiewicz Commented Jan 15, 2012 at 9:56
  • I checked this link janmatuschek.de/LatitudeLongitudeBoundingCoordinates (section 3.1) sort out with some formula,But it is not matching with the circle drawn at 20km – Nishu Commented Jan 15, 2012 at 10:00
  • i apologize, here longitude will be fixed that is in Point A = (18.5204303,73.8567437) Point B = (x,73.8567437) Distance =20KM(Kilometers) – Nishu Commented Jan 15, 2012 at 10:03
 |  Show 5 more ments

3 Answers 3

Reset to default 3

i found answer for my question

var lat1 = 18.5204303;
    var lon1 = 73.8567437;
    var d = 20;   //Distance travelled
    var R = 6371;
    var brng = 0;
    var LatMax;
    brng = toRad(brng); 
    var lat1 = toRad(lat1), lon1 = toRad(lon1);
    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));
        lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI;  
    lat2= toDeg(lat2);
    lon2= toDeg(lon2);
    alert(lat2);
    alert(lon2);

function toRad(Value) {
    /** Converts numeric degrees to radians */
    return Value * Math.PI / 180;
}
 function toDeg(Value) {
   return Value * 180 / Math.PI;
}

Thank you all

I'm not sure if this should be an answer or a ment. But since I can't write ments yet I'll write an answer.

This page is a great source for doing distance calculations. In this case you are probably looking for code to calculate the new position when traveling along a rhumb line from a given position. Quote from linked page:

To find the lat/lon of a point on true course tc, distance d from (lat1,lon1) along a rhumbline (initial point cannot be a pole!):

lat= lat1+d*cos(tc)
IF (abs(lat) > pi/2) "d too large. You can't go this far along this rhumb line!"
IF (abs(lat-lat1) < sqrt(TOL))
{
    q=cos(lat1)
}
ELSE 
{
    dphi=log(tan(lat/2+pi/4)/tan(lat1/2+pi/4))
    q= (lat-lat1)/dphi
}
dlon=-d*sin(tc)/q
lon=mod(lon1+dlon+pi,2*pi)-pi

The link is still useful but you will have to use some algebra to solve for a known longitude and unknown course. Since you are quite far north great circle distances may be more useful than rhumb lines. But I guess that depends on the problem.

I am not an expert in this. But i used to calculate the distance between two points using the formulae by movable-type.

Please check the site. it ll give you some hint. I think this destination and rhumblines formulae are similar to your requirement. Have a look

发布评论

评论列表(0)

  1. 暂无评论