【问题标题】:Going through latitude and longitude of a country穿越一个国家的经纬度
【发布时间】:2015-09-27 07:02:17
【问题描述】:

我有一个有趣的项目。

所以我有一个 WEB API,它接收两个参数,经度和纬度,并响应 true 或 false 是否存在中心(纬度,经度)和无线电 X(假设 10 英里)的圆圈中的一些资源。

如果它响应 true,我必须再次调用它,直到它响应 False。

如果它响应为假,我不必再次调用它

当我弄错时,我必须更改(纬度,经度),因此我在不同于前一个区域的其他区域搜索这些资源,直到我覆盖一个国家的所有领土。 我想用 python 自动化它以覆盖所有美国领土。我该怎么做?

我正在考虑从圣地亚哥(美国左下角)出发,一直到西雅图或类似的地方。但是,我怎么知道美国领土的分隔符(纬度和经度)。

我不知道我是否正确解释了我想要做什么。如果没有,请告诉我,我会努力的。

谢谢

【问题讨论】:

    标签: python api geolocation latitude-longitude


    【解决方案1】:

    您可以使用geopy 第三方模块上提供的 vincenty 距离功能。您必须使用pip install geopypypi 安装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.
    

    有关更多信息,请参阅 geopy 文档:https://geopy.readthedocs.org/en/1.10.0/#module-geopy.distance

    【讨论】:

      猜你喜欢
      • 2016-10-10
      • 2011-05-28
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多