0

I am trying to write a JavaScript web application that allows me to get a random location that has Google Street-view information.

The first step I took was to create a random latitude and longitude location, however as the Earth is mostly ocean, I ended up there more often than not. I then tried to use the closest location to those randomly selected points, however that made me end up on the shore, or in random underwater locations most of the time.

I also tried using an API to get lists of random on-land location, however that also included locations slightly off-shore, and often did not land on a street-view area (or near to one). It was close, but didn't give me the best result.

The goal is to do this as efficiently as possible, while maintaining a relatively low amount of API calls.

As far as I could find, google does not publish a list of all of the locations with street-view information, which limits my possibilities for randomly selecting a location from a list.

I'm trying to achieve the effect of GeoGuessr.

Spiralio
  • 361
  • 1
  • 4
  • 15
  • 1
    Years ago I played a game called Geoguessr - it has evolved (i.e. been ruined) some way now, but it used to place you on a random point in street view and you had to attempt to determine your location navigating Streetview. The point is, this must be able to be done. – LTPCGO Sep 15 '19 at 00:47

2 Answers2

0

There are some APIs you could use to get a random coordinates

for example:

https://api.3geonames.org/?random=yes random location API of 3geonames might help

and, if you want to pick a random location at or near land https://api.3geonames.org/?randomland=yes (since most of the surface of the earth is covered by oceans)

You can also add country code as a parameter in this API (eg., Germany - DE): https://api.3geonames.org/?randomland=DE

then, you could check the validity of those coordinates in Google Static API and get the final pano data from Street View Service

-1

StreetViewService

In their docs google describes how to get a streetview location.

See also this answer on stack overflow describing an example implementation.

Reverse geocoding

If that doesn't work for you; I think your approach of reverse-geocoding random LatLon wouldn't be that bad.

In their docs google describes request parameters for their reverse geocoder.

Perhaps you could use street or route as the result_type to at least narrow it down by a lot.

Webber
  • 4,672
  • 4
  • 29
  • 38
  • 1
    The problem with this would be that since it is more likely to land in the ocean, locations near the coast as well as islands are disproportionally picked. – Spiralio Sep 15 '19 at 01:04
  • I ended up going with a variation of this answer. I used reverse geocoding to get the nearest streetview location to an api that found that gives a random on land location. I then manually coded some rectangular areas where streetview was not available, to avoid getting large areas like russia without any street view. – Spiralio Sep 15 '19 at 18:14