i have a map application that inserts map pins when the user moves to certain locations, my question is how do i count the number of times the user has passed or has been on that same place.
Has in the following example:
User has been on place A with (latitude, longitude) five times.
Here is the code i have so far:
[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];
Sorry for my poor english, please dont down rate, any question or doubt just aks me im always online.
You could set up a region around each pin and tell the cllocationmanager to tell you when the device gets close.
When you get a callback (the delegate method
didEnterRegion) you can increment a counterI’ll leave it to you to work out which counter you need to increment for each region