Google地图 - 获取给定半径范围内的所有标记

时间:2018-01-06 23:31:12

标签: ios api google-maps maps

我正在使用iOS应用程序,我希望它能够显示给定半径内的所有标记。

我使用GMSGeometryDistance计算所有标记距离并返回给定半径范围内的距离。

当前位置在高频率上变化。这意味着我需要在每次更改位置时进行计算,这会影响应用程序的性能。

是否有任何功能可以在用户移动的每个给定距离内计算它?

1 个答案:

答案 0 :(得分:0)

<p>
I get all the markers with in the given radius by using below code.Please check it once.Hope it will help to you. </p>
<p>

<table>
<tr>
`CLLocationDistance dist = 800; // required radius in meters.
</tr>
<tr>
CLLocation *closestLocation;
</tr>
<tr>
// finalArr(NsMutableArray) stores coordinates fetching from database
</tr>
<tr>
for (CLLocation *location in finalArr) {
</tr>
<tr>
CLLocationDistance distance = [currentLoc  distanceFromLocation:location];
</tr>
<tr>
        if (distance < dist) {
</tr>
<tr>
closestLocation = location;
</tr>
<tr>
[closeLatArr addObject:@(closestLocation.coordinate.latitude)];
</tr>
<tr>
[closeLongArr addObject:@(closestLocation.coordinate.longitude)];
</tr>
<tr>
}
</tr>
<tr>
for (int i=0; i<[closeLatArr count]; i++) {

        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake([[closeLatArr objectAtIndex:i] doubleValue], [[closeLongArr objectAtIndex:i] doubleValue]);

        //   marker.title = [locArr objectAtIndex:i];
        marker.map = mapView;
        //NSLog(@"closest loc are %@",locArr);

    }`
</tr>
</table>
</p>
相关问题