【问题标题】:Find places within the boundaries of given locations查找给定位置边界内的位置
【发布时间】:2015-02-19 13:30:30
【问题描述】:

在我的地图应用程序中,我必须找到选定位置范围内的地点(银行、ATM、咖啡馆、酒吧..)。实际上,我必须找到位于给定位置中心的地点。

例如,我有 4 个地方 a、b、c、d,我必须让所有银行都在这 4 个地方的范围内,并在地图上显示它们。

我可以使用 GooglePlaces API 分别获取每个位置最近的地点。但我需要显示位于这 4 个地点的中心(大约)的地点。

请给我任何建议或任何示例代码或任何其他教程或链接......

谢谢

拉基。

【问题讨论】:

    标签: ios objective-c google-maps google-maps-api-3 mapkit


    【解决方案1】:

    您的解决方案是获取您点的平均纬度/经度,然后点击您的 Google API 以获取该区域的位置。不管你有多少坐标,这个平均值都在中间。示例:

    double totalLat = 0;
    double totalLon = 0;
    
    for(CLLocationCoordinate2D coordinate in coordinateArray)
    {
        totalLat += coordinate.latitude;
        totalLon += coordinate.longitude;
    }
    
    // Use this average coordinate (which is the center of your points) to hit your Google API
    CLLocationCoordinate2D averageCoordinate = CLLocationCoordinate2DMake(totalLat / coordinateArray.count, totalLon / coordinateArray.count);
    

    注意:我还没有实际测试过这个,所以不要只是复制/粘贴,但这是一般的想法。

    【讨论】:

    • @raki 如果解决方案对您有用,请考虑将其标记为已接受的答案,以便从未回答的问题列表中清除。
    【解决方案2】:

    您始终可以使用 Places API 中定义的半径参数来获取此信息。

    请关注此 Stack Overflow answer 了解更多详情。

    【讨论】:

    • 如果有很多位置,很难为每个位置调用具有半径的搜索 api 并找到离所有这些位置最近的位置....对吗?
    猜你喜欢
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 2011-12-28
    • 2018-08-13
    • 1970-01-01
    相关资源
    最近更新 更多