我有一个地图应用程序,当用户移动到某些位置时插入地图引脚,我的问题是我如何计算用户已经过或在同一个地方的次数。
在以下示例中有:
用户已经在地点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];
抱歉我的英语不好,请不要降价,任何疑问或疑问只会让我永远在线。
答案 0 :(得分:1)
您可以在每个引脚周围设置一个区域,并告诉cllocationmanager告诉您设备何时关闭。
CLLocationAccuracy acc = kCLLocationAccuracyNearestTenMeters;
[self.locationManager startMonitoringForRegion:aRegion desiredAccuracy:acc];
当你得到一个回调(委托方法didEnterRegion
)时,你可以增加一个计数器
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"GeoFence: didEnterRegion");
}
我会留给你找出你需要为每个区域增加的计数器
答案 1 :(得分:0)
您已使用[对象计数]的引脚数。