Created
June 6, 2024 16:47
-
-
Save codergautam/772188511c39f9a4fe4228449547f551 to your computer and use it in GitHub Desktop.
Check if a Google street view exists at a specific latitude and longitude - NodeJS No api key
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
async function hasStreetViewImage(lat, long, radius) { | |
const url = `https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d${lat}!4d${long}!2d${radius}!3m18!2m2!1sen!2sUS!9m1!1e2!11m12!1m3!1e2!2b1!3e2!1m3!1e3!2b1!3e2!1m3!1e10!2b1!3e2!4m6!1e1!1e2!1e3!1e4!1e8!1e6&callback=_xdc_._2kz7bz`; | |
const response = await fetch(url, { | |
headers: { | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/59.0.3071.109 Chrome/59.0.3071.109 Safari/537.36' | |
} | |
}); | |
const text = await response.text(); | |
return !text.includes("Search returned no images"); | |
} | |
// Example usage: | |
hasStreetViewImage(40.714224, -73.452, 10).then(hasImage => { | |
console.log(hasImage); // true or false | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment