Skip to content

Instantly share code, notes, and snippets.

@mariohmol
Created July 12, 2018 19:11
Show Gist options
  • Save mariohmol/3e207589f3be015c234d6310e6cedc26 to your computer and use it in GitHub Desktop.
Save mariohmol/3e207589f3be015c234d6310e6cedc26 to your computer and use it in GitHub Desktop.
geospatial
const makeSquareAreaFromLatLng = function (lat, lng, distance = 10) {
const lat_change = distance / 111.2;
const lon_change = (Math.abs(Math.cos(lat * (Math.PI / 180)))) / 4;
const circlePoints = [];
const bounds = {
lat_min: lat - lat_change,
lon_min: lng - lon_change,
lat_max: lat + lat_change,
lon_max: lng + lon_change
};
circlePoints.push([bounds.lon_min, bounds.lat_max]);
circlePoints.push([bounds.lon_max, bounds.lat_max]);
circlePoints.push([bounds.lon_max, bounds.lat_min]);
circlePoints.push([bounds.lon_min, bounds.lat_min]);
circlePoints.push([bounds.lon_min, bounds.lat_max]);
return circlePoints;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment