Last active
January 24, 2018 21:49
-
-
Save parappathekappa/d71e5c1ddb4b21592d64c24d15bf10fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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