0

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

在以下示例中有:

用户已在(纬度,经度)地点 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];

对不起,我的英语很差,请不要降价,任何问题或疑问都会问我,我总是在线。

4

2 回答 2

1

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

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

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

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

我会留给你来计算你需要为每个区域增加哪个计数器

于 2012-11-19T20:48:53.813 回答
0

您已经使用 [objects count] 获得了引脚数。

于 2012-11-19T13:17:44.473 回答