我有一个 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/