Search code examples
javascriptrandomgeocoding

Generate random latitude/longitude while avoiding oceans


I'm using https://randomuser.me/ to generate some random user data for testing. I'd like to geocode the latitude and longitude that provides to attach the real city/state/country information instead of the totally fake info that RandomUser provides. However, many of the actual lat/long values on these objects turn out to be in the middle of the ocean.

Is there an API, or some other method, that will let me get random coordinates which are always over land? I've seen this: Random geographic coordinates (on land, avoid ocean) But surely there must be some more efficient way than to just guess-and-check with constant geocoding until you find one that works, right?


Solution

  • https://3geonames.org/ Click on "Pick a random location at or near land"

    The API is here: https://api.3geonames.org/?randomland=yes (for a random location on land)

    or https://api.3geonames.org/?random=yes for any other kind of random location.

    Update: As of September 2020 you can pick a random location in any given country. For example https://3geonames.org/randomland.NL will return a random location in the Netherlands.