【问题标题】:Google maps - get all markers inside a given radius谷歌地图 - 获取给定半径内的所有标记
【发布时间】:2018-06-16 09:46:21
【问题描述】:

我正在开发一个 iOS 应用程序,我希望它显示给定半径内的所有标记。

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

当前位置会频繁变化。这意味着每次更改位置时我都需要计算此值,这会影响应用性能。

是否有任何函数可以计算用户移动的每个给定距离?

【问题讨论】:

    标签: ios api google-maps maps


    【解决方案1】:
    <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>
    

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多