如何通过移动固定距离获取经纬度点(for google地图扫描window)?

How to get the latitude and longitude point by shifting fixed distance (for google map scanning window)?

我想搜索某个国家的一些店铺,例如:

Find all Nike stores in US.

我使用 Google Map Place API 实现了它。但是我发现 Google API 好像不能搜索位于特定国家的目标,而且它还限制了搜索半径(50000米)。

所以,我现在正在尝试使用如下所示的“扫描 window”,这是我能想到的最可行的方法。

主要概念是给两个经纬度点(img中的蓝点)做一个平面,程序会把这个区域切成许多半径固定的小圆圈。然后我们可以使用每个圆的中心(红点)来查询 Google API.

但是当我使用切片功能时,如果我想按距离移动一个点,我知道如何获得这些红点...

有谁知道如何实现这个功能?或者还有其他方法可以实现我的目标吗?

非常感谢。

我刚刚找到了解决这个问题的方法,这是我的示例代码:

from geopy import distance


# slice the big area into small ones for Google map radius restriction problem
def slice_search_area(point_a=(None, None), point_b=(None, None), region=None, radius=50000):
    if (None in point_a) or (None in [point_b]):
        return []
    p1 = point_a
    p2 = (point_a[0], point_b[1])
    p3 = point_b
    p4 = (point_b[0], point_a[1])

    # get the start point (move East first, then move South)
    tmp_point = distance.distance(meters=radius).destination(p1, bearing=90)
    start_point = distance.distance(meters=radius).destination(tmp_point, bearing=180)

    # get every (latitude, longitude) of the points
    scan_points = list()
    row_start_point = start_point
    while row_start_point[0] > p4[0]:
        point = row_start_point
        while point[1] < p2[1]:
            # save (latitude, longitude)
            scan_points.append((point.latitude, point.longitude))

            # point move East
            point = distance.distance(meters=radius).destination(point, bearing=90)

        row_start_point = distance.distance(meters=radius).destination(row_start_point, bearing=180)
    
    return scan_points

这是我的测试代码:

country_area = {
    'tw': [(25.34141, 120.10243), (21.959811, 121.986222)]
}

a = country_area['tw'][0]
b = country_area['tw'][1]
p = slice_search_area(a, b, 'tw')
for each in p:
    print(each)

结果:

(24.889205690304994, 120.59910323641213)
(24.88838533068927, 121.0939524816418)
(24.887565001719338, 121.5887984580001)
(24.437811397277283, 120.59910323641213)
(24.437007840789235, 121.09217552708851)
(24.436204314108405, 121.58524469306849)
(23.98639017250887, 120.59910323641213)
(23.985603303344558, 121.09044150686496)
(23.98481646316774, 121.58177679194344)
(23.53494238775737, 120.59910323641213)
(23.53417209335193, 121.08874975902926)
(23.5334018271324, 121.57839343089873)
(23.083468421486256, 120.59910323641213)
(23.082714592440123, 121.08709964298127)
(23.081960790795765, 121.57509332888482)
(22.631968658771996, 120.59910323641213)
(22.631231188779743, 121.08549053882054)
(22.630493745421962, 121.57187524624496)
(22.180443491209363, 120.59910323641213)
(22.179722276991253, 121.0839218467313)
(22.179001088656495, 121.56873798348572)

如果我在 Google 地图上标记点,我可以得到:

可以通过Google地图API.

搜索每个圈内的目标