Skip to content

Instantly share code, notes, and snippets.

@parappathekappa
Last active January 24, 2018 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parappathekappa/d71e5c1ddb4b21592d64c24d15bf10fa to your computer and use it in GitHub Desktop.
Save parappathekappa/d71e5c1ddb4b21592d64c24d15bf10fa to your computer and use it in GitHub Desktop.
// Inputs
// location: location object
// distance: array of distances in meters
getMultipleAddressesFromApi = {location, distance} => {
pointsHolder = [];
// Earth's radius
R = 6371000;
// Array of radians
radiansArray = [
0,
0.75,
1.57,
2.32,
3.14,
3.89,
4.71,
5.46
];
// Cycle between distance array
for each (d in distance) {
// add original lat lng values from location
mylat = location.coords.latitude;
mylon = location.coords.longitude;
pointsHolder.push([mylat, mylon]);
// cycle through radiansArray to generate new points
for (i = 0; i < radiansArray.length; i++) {
brng = radiansArray[i];
mylatrad = mylat * Math.PI / 180;
mylonrad = mylon * Math.PI / 180;
var newlatrad = Math.asin(
Math.sin(mylatrad) * Math.cos(d / R) +
Math.cos(mylatrad) * Math.sin(d / R) * Math.cos(brng)
);
var newlonrad =
mylonrad +
Math.atan2(
Math.sin(brng) * Math.sin(d / R) * Math.cos(mylatrad),
Math.cos(d / R) - Math.sin(mylatrad) * Math.sin(newlatrad)
);
newlat = newlatrad / Math.PI * 180;
newlon = newlonrad / Math.PI * 180;
pointsHolder.push([newlat, newlon]);
}
}
for each (point in pointsHolder) {
this.getAddressesFromApi(point[0], point[1]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment