Random geographic coordinates (on land, avoid ocean)

前端 未结 16 1161
死守一世寂寞
死守一世寂寞 2020-12-08 10:03

Any clever ideas on how to generate random coordinates (latitude / longitude) of places on Earth? Latitude / Longitude. Precision to 5 points and avoid bodies of water. <

16条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 10:20

    Supplementary to what bsimic said about digging into GeoNames' Webservices, here is a shortcut:
    they have a dedicated WebService for requesting an ocean name.

    (I am aware the of OP's constraint to not using public web services due to the amount of requests. Nevertheless I stumbled upon this with the same basic question and consider this helpful.)

    Go to http://www.geonames.org/export/web-services.html#astergdem and have a look at "Ocean / reverse geocoding". It is available as XML and JSON. Create a free user account to prevent daily limits on the demo account.

    Request example on ocean area (Baltic Sea, JSON-URL):

    http://api.geonames.org/oceanJSON?lat=54.049889&lng=10.851388&username=demo

    results in

    {
      "ocean": {
        "distance": "0",
        "name": "Baltic Sea"
      }
    }
    

    while some coordinates on land result in

    {
      "status": {
        "message": "we are afraid we could not find an ocean for latitude and longitude :53.0,9.0",
        "value": 15
      }
    }
    

提交回复
热议问题