Random geographic coordinates (on land, avoid ocean)

前端 未结 16 1159
死守一世寂寞
死守一世寂寞 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:27

    To get a nice even distribution over latitudes and longitudes you should do something like this to get the right angles:

    double longitude = Math.random() * Math.PI * 2;
    double latitude = Math.acos(Math.random() * 2 - 1);
    

    As for avoiding bodies of water, do you have the data for where water is already? Well, just resample until you get a hit! If you don't have this data already then it seems some other people have some better suggestions than I would for that...

    Hope this helps, cheers.

提交回复
热议问题