开发者

Need to find lats & long of a location which is about 50km away from a location

I need to find lats and long of a开发者_Python百科ny point which is about 50km away from a particular Point. How do I do it?


This will get you pretty close, it is based off of the equations and example code available here:

window.pointsAround = function(centerLat, centerLng, radius) {
    var result = [];

    //do annoying trig maths to work out the delta in latitude between our start and end points
    var targetD = radius;          //km
    var R = 6371;                  //km
    var c = (targetD / R) / 2;
    var sqrtA = Math.sin(c);
    var a = sqrtA * sqrtA;
    var sinHalfDLat = Math.sqrt(a);
    var dLat = Math.asin(sinHalfDLat) * 2;
    var dLatDegrees = ((dLat / (2 * Math.PI)) * 360);

    var minLat = centerLat - dLatDegrees;            //furthest valid latitude above the origin
    var maxLat = centerLat + dLatDegrees;            //furthest valid latitude below the origin

    //alert("minLat=" + minLat + ", maxLat=" + maxLat + ", dLat=" + dLat + ", dLatDegrees=" + dLatDegrees);

    //topmost and bottommost points in the circle
    result.push({lat: minLat, lng: centerLng});
    result.push({lat: maxLat, lng: centerLng});

    //step from minLat to maxLat, interpolating coordinates that lie upon the circle
    var step = (maxLat - minLat) / 180.0;
    for (var count = 0; count < 179; count++) {
        minLat += step;
        dLat = (centerLat - minLat) * Math.PI / 180;

        //more annoying trig to work out the delta in longitude for our interpolated coordinate
        var dLon = 2 * Math.asin(Math.sqrt((a - (Math.sin(dLat/2) * Math.sin(dLat/2))) / (Math.cos(minLat) * Math.cos(centerLat))));
        var dLonDegrees = ((dLon / (2 * Math.PI)) * 360);

        var newLng = centerLng + dLonDegrees;
        var deltaLng = newLng - centerLng;
        result.push({lat: minLat, lng: newLng});
        result.push({lat: minLat, lng: centerLng - deltaLng});
    }

    return result;
};

Sorry for the terrible variable names, as I said they are based upon the sample implementation, which uses the same names.

Here is a working example: http://jsfiddle.net/HmchC/8/

The plot is more elliptical than I would like, but meh. That's as close as I can get it, for now.

Update

I fixed the issue with the elliptical plotting, it was just missing a conversion from degrees to radians. When will math people learn that only degrees make sense?

In any case, working example here: http://jsfiddle.net/HmchC/11/


hmmm, not especially clear what you are after here.

If you have a known point (with known lat and long) and are after latitude and longitude of points lying on the circumference of a 50km circle around the known point?

Thats how I read it anyway....you could do this with some math I suppose. A constant distance such as kilometer will equate to a constant change in lat/long which you can calculate and define. Where its going to get tricky is determining how much of this change to apply to lat and how much to long, i suppose you could use a compass bearing if the device supports one

Edit: assuming we are correct about what you want then the link in Aroth's comment should help you out


You want to look for the harvesine formula or a space-filling-curve or a spatial index. The harvesine formula calculates the collision of 2 circles and the space-filling-curve recursively subdivide the map into tiles. It looks like a quadtree and it reduces the 2d complexity to a 1d complexity. You want to look for a unique key or quadrant to lookup for near by points. You want to look into Nick's hilbert curve spatial index quadtree blog.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜