Python 穿越一个国家的经纬度
我有一个有趣的项目 因此,我有一个WEB API,它接收两个参数,经度和纬度,并响应true或false。如果是true,则在一个中心为lat、long和radio X的圆圈中有一些资源,比如说10英里 如果它响应为真,我必须再次调用它,直到它响应为假 如果它的响应为false,我就不必再次调用它 当我得到错误,我必须改变lat,长,所以我在其他领域搜索这些资源不同于前一个,直到我覆盖了一个国家的所有领土。 我想用python将其自动化,例如覆盖所有美国领土。我怎么做 我想从美国左下角的圣地亚哥出发,一直到西雅图或者类似的地方。但是,我怎么知道美国领土的纬度和经度呢 我不知道我是否正确地解释了我想做什么。如果没有,请告诉我,我会努力做得更好Python 穿越一个国家的经纬度,python,api,geolocation,latitude-longitude,Python,Api,Geolocation,Latitude Longitude,我有一个有趣的项目 因此,我有一个WEB API,它接收两个参数,经度和纬度,并响应true或false。如果是true,则在一个中心为lat、long和radio X的圆圈中有一些资源,比如说10英里 如果它响应为真,我必须再次调用它,直到它响应为假 如果它的响应为false,我就不必再次调用它 当我得到错误,我必须改变lat,长,所以我在其他领域搜索这些资源不同于前一个,直到我覆盖了一个国家的所有领土。 我想用python将其自动化,例如覆盖所有美国领土。我怎么做 我想从美国左下角的圣地亚哥
谢谢您可以使用geopy第三方模块上提供的vincenty距离功能。您必须使用pip install geopy从pypi安装geopy 下面是如何编写代码的示例:
from geopy.distance import vincenty
this_country = (latitude, longitude)
radius = 10 # 10 miles
while radius >= 0:
other_country_within_circle_found = False
# other_countries is a list of tuples which are lat & long
# positions of other country eg. (-12.3456, 78.91011)
for other_country in other_countries:
# note: other_country = (latitude, longitude)
if other_country == this_country:
continue # skip if other country is the same as this country.
distance = vincenty(this_country, other_country).miles
if distance <= radius:
other_country_within_circle_found = True
break
if not other_country_within_circle_found:
# the circle of this radius, have no other countries inside it.
break
radius -= 1 # reduce the circle radius by 1 mile.
有关更多信息,请参阅地质资料文档: