Skip to content

Instantly share code, notes, and snippets.

@oliverswitzer
Last active August 25, 2021 04:37
Show Gist options
  • Save oliverswitzer/7243e99d87ffda8a69a77407c795a8c6 to your computer and use it in GitHub Desktop.
Save oliverswitzer/7243e99d87ffda8a69a77407c795a8c6 to your computer and use it in GitHub Desktop.
Small script that helps you locate hotspots from https://app.hotspotty.net/ in Google Earth. Just click the bookmarklet after navigating to the current selected hotspots "info" tab. To create bookmarklet, copy contents of bookmarklet.js, create a new empty bookmark, and paste into the bookmark. You can also make it yourself using this tool https…
javascript:(function()%7BopenGoogleEarthForHotspot()%3B%0Afunction earthUrl(lat%2C lng) %7B%0A return %60https%3A%2F%2Fearth.google.com%2Fweb%2Fsearch%2F%24%7Blat%7D%2C%24%7Blng%7D%60%3B%0A%7D%0A%0Aasync function openGoogleEarthForHotspot() %7B%0A const hotspotAddress %3D getHotspotAddress()%3B%0A const %7B lat%2C lng %7D %3D await getCoordinates(hotspotAddress)%3B%0A window.open(earthUrl(lat%2C lng))%3B%0A%7D%0A%0Aasync function getCoordinates(hotspotAddress) %7B%0A const res %3D await fetch(%0A %60https%3A%2F%2Fapi.helium.io%2Fv1%2Fhotspots%2F%24%7BhotspotAddress%7D%60%0A ).then((res) %3D> res.json())%3B%0A const %7B lng%2C lat %7D %3D res.data%3B%0A%0A return %7B lng%2C lat %7D%3B%0A%7D%0A%0Afunction getHotspotAddress() %7B%0A var xpath %3D "%2F%2F*%5Bcontains(text()%2C'Hotspot address')%5D"%3B%0A var matchingElement %3D document.evaluate(%0A xpath%2C%0A document%2C%0A null%2C%0A XPathResult.FIRST_ORDERED_NODE_TYPE%2C%0A null%0A ).singleNodeValue%3B%0A%0A return matchingElement.nextSibling %26%26 matchingElement.nextSibling.innerText%3B%0A%7D%7D)()%3B
openGoogleEarthForHotspot();
function earthUrl(lat, lng) {
return `https://earth.google.com/web/search/${lat},${lng}`;
}
async function openGoogleEarthForHotspot() {
const hotspotAddress = getHotspotAddress();
const { lat, lng } = await getCoordinates(hotspotAddress);
window.open(earthUrl(lat, lng));
}
async function getCoordinates(hotspotAddress) {
const res = await fetch(
`https://api.helium.io/v1/hotspots/${hotspotAddress}`
).then((res) => res.json());
const { lng, lat } = res.data;
return { lng, lat };
}
function getHotspotAddress() {
var xpath = "//*[contains(text(),'Hotspot address')]";
var matchingElement = document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
return matchingElement.nextSibling && matchingElement.nextSibling.innerText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment