Skip to content

Instantly share code, notes, and snippets.

@kototoibashi
Created February 19, 2020 11:01
Show Gist options
  • Save kototoibashi/a2f6b571b26f4487fa425ff57b002df1 to your computer and use it in GitHub Desktop.
Save kototoibashi/a2f6b571b26f4487fa425ff57b002df1 to your computer and use it in GitHub Desktop.
LatLng to 100m Meshcode
const latlng_to_mesh = (latlng) => {
return [
(latlng[0] - 0) / (1/60/60*30/10),
(latlng[1] - 100) / (1 / 60 / 60 * 45/10)
]
}
const latlng_to_meshcode = (latlng) => {
const mesh = latlng_to_mesh(latlng)
const lat3 = ("00000" + Math.floor(mesh[0])).slice(-5)
const lon3 = ("00000" + Math.floor(mesh[1])).slice(-5)
const lat2 = ("000" + Math.floor(mesh[0] / 100)%8).slice(-1)
const lon2 = ("000" + Math.floor(mesh[1] / 100)%8).slice(-1)
const lat1 = ("000" + Math.floor(mesh[0] / 800)).slice(-2)
const lon1 = ("000" + Math.floor(mesh[1] / 800)).slice(-2)
console.log(mesh[0])
console.log(mesh[1])
console.log(mesh[0]/80)
console.log(mesh[1]/80)
console.log(lat2)
console.log(lon2)
console.log(lat3)
console.log(lon3)
return lat1.charAt(0) + lat1.charAt(1) + lon1.charAt(0) + lon1.charAt(1)
+ lat2.charAt(0) + lon2.charAt(0)
+ lat3.charAt(3) + lon3.charAt(3)
+ lat3.charAt(4) + lon3.charAt(4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment