iphone - 计算 map 图钉

标签 iphone objective-c ios mapkit

我有一个 map 应用程序,当用户移动到某些位置时,它会插入 map 图钉,我的问题是如何计算用户经过或去过同一地点的次数。

在以下示例中有:

用户已到过地点 A (纬度、经度)五次。

这是我到目前为止的代码:

[outletMapView setMapType:MKMapTypeStandard];
                    [outletMapView setZoomEnabled:YES];
                    [outletMapView setScrollEnabled:YES];

                    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
                    region.center.latitude = [[eachObject objectForKey:@"latitudeFrom"] floatValue];
                    //NSLog(@"latitudeFrom=%f",[[eachObject objectForKey:@"latitudeFrom"] floatValue]);
                    region.center.longitude = [[eachObject objectForKey:@"longitudeFrom"] floatValue];
                    //NSLog(@"longitudeFrom=%f",[[eachObject objectForKey:@"longitudeFrom"] floatValue]);
                    region.span.longitudeDelta = 6;
                    region.span.latitudeDelta = 7;
                    [outletMapView setRegion:region animated:YES];
                    /////
                    float longitude = [[eachObject objectForKey:@"latitudeFrom"] floatValue];
                    float latitude = [[eachObject objectForKey:@"longitudeFrom"] floatValue];

                    CLLocationCoordinate2D locationco = {latitude,longitude};

                    ann = [[DisplayMap alloc] init];
                    ann.coordinate = locationco;
                    ann.title = [eachObject objectForKey:@"setDepartureAirportOrCode"];

                    int count=0;
                    for(int j = aux; j < [objects count]; j++){
                        for(int k = j+1;k < [objects count]-j;k++){
                            NSMutableDictionary *item1 = [objects objectAtIndex:j];
                            NSMutableDictionary *item2 = [objects objectAtIndex:k];

                            NSString *str1 = [item1 valueForKey:@"setDepartureAirportOrCode"];
                            NSString *str2 = [item2 valueForKey:@"setDepartureAirportOrCode"];
                           // NSLog(@"%@==%@ ???",str1,str2);
                            if([str1 isEqualToString:str2])
                                 NSLog(@"%@==%@ MATCH!!!",str1,str2);
                                count++;
                        }
                    }



                    /* Contagem */

                    ann.subtitle = [NSString stringWithFormat:@"%d",count];
                    ann.coordinate = region.center;
                    [outletMapView addAnnotation:ann];

抱歉我的英语不好,请不要 Markdown ,任何问题或疑问都可以问我,我总是在线。

最佳答案

您可以在每个引脚周围设置一个区域,并告诉 cllocationmanager 在设备靠近时通知您。

CLLocationAccuracy acc = kCLLocationAccuracyNearestTenMeters;
[self.locationManager startMonitoringForRegion:aRegion desiredAccuracy:acc];

当您收到回调(委托(delegate)方法didEnterRegion)时,您可以增加计数器

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
   NSLog(@"GeoFence: didEnterRegion");    
}

我将让您自行决定需要为每个区域增加哪个计数器

关于iphone - 计算 map 图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13451608/

相关文章:

ios - 桥接 header 中导入的文件数量是否会影响编译时间?

ios - 像键盘一样显示 UIPickerView,没有 UITextField

iphone - UIWebView 泄漏?有人可以确认吗?

iphone - 使用Web服务刷新时如何知道数据是否更新

ios - IMP methodForSelector EXC_BAD_ACCESS 崩溃

objective-c - 有没有办法在 AFNetworking 的后台线程上构建模型对象?

ios - iphone 5S 导出视频时慢动作没有了

ios - 用于应试 iOS 应用程序的核心数据模型

iphone - 未检测到 iPad 启动方向

ios - 为简单的触摸调用 scrollViewDidEndDecelerating