Javascript bounding box calculation

I have latitude / longitude value and distance value. I need to calculate a bounding box with a given location as the center. therefore, if the distance was 200 meters, the rectangle should be 200 meters in front, behind, left, and right.

How do I do this using JavaScript?

+3
source share
3 answers

You need to translate the lat / long coordinate to the x / y value in the projection of the map you are using, then you can calculate your bounding box.

API Google, , . GBounds, GMercatorProjection GLatLngBounds . API Google , , Proj4js. , , " " . Google Maps .

+3

javascript :

http://www.movable-type.co.uk/scripts/latlong.html

javascript :

LatLon.prototype.boundingBox = function (distance)
{
    return [
        this.destinationPoint(-90, distance)._lon,
        this.destinationPoint(180, distance)._lat,
        this.destinationPoint(90, distance)._lon,
        this.destinationPoint(0, distance)._lat,
    ];
}

( " " .

+3

If you use the V3 API , you can use Rectangle and Circle . See a brief description and examples of this blogger:

http://apitricks.blogspot.com/2010/02/rectangle-and-circle-of-v3.html

0
source

Source: https://habr.com/ru/post/1752333/