在我的地图应用程序中,我必须找到所选位置范围内的地方(银行,自动取款机,咖啡厅,酒吧......)。实际上我必须得到位于给定位置中心的地方。
例如我有4个地方a,b,c,d我必须在这4个地方的范围内获得所有银行并在地图上显示它们。
我可以使用GooglePlaces API单独获取每个位置的最近位置。但我需要显示位于这4个位置中心(大约)的位置。
请给我任何建议如何执行此操作或任何示例代码或任何其他教程或链接....
由于
Raki酒。
答案 0 :(得分: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);
注意:我实际上没有测试过这个,所以不要只是复制/粘贴,但这是一般的想法。
答案 1 :(得分:0)
您始终可以使用Places API中定义的radius参数来获取此信息。
请按照此Stack Overflow answer了解详情。