I am having problems to get this work , I using core data to fetch a list of User ,
NSFetchrequets to extra the user location , List of Places and Postcode

NSFetchRequest *request =[NSFetchRequest fetchRequestWithEntityName:@"SiteLocation"]; //request all objects
NSArray *fetchedObjects = [self.srmDatabase.managedObjectContext executeFetchRequest:request error:nil];
So I have a Entity “SiteLocation” loading the tableview with FetchedResultController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"CELL");
static NSString *CellIdentifier = @"Site Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
SiteLocation * siteLocation = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = siteLocation.siteName;
return cell;
}
then I sent the selected row to the MapViewController didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didselect sitePC");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UserDetails *userinfo = [[self fetchedResultsController] objectAtIndexPath:indexPath];
self.mapview.sitePC = userinfo; //sitePC is (id)
NSLog(@"object selected= %@", userinfo);
}
}
2012-10-04 13:27:46.401 SRMAB[459:c07] didselect sitePC = <SiteLocation: 0x1d80ad20> (entity: SiteLocation; id: 0x1d86b210 <x-coredata://523E1EB6-01DF-4889-B1A1-2E38E92D385E/SiteLocation/p120> ; data: {
projectName = (
"0x1d82bc20 <x-coredata://523E1EB6-01DF-4889-B1A1-2E38E92D385E/UserDetails/p144>"
);
siteName = "Bloomberg Place 1";
sitePostCode = "W1B 5AU";
})
On the MapViewController this will convert the sitePostcode to PlaceMark
-(void)myMapview
{
NSLog(@"mymapview");
NSString *addressString = [self.sitePC valueForKey:@"sitePostCode"];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(@"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark1 in placemarks)
{
NSLog(@"Placemark: %@",placemark1);
//[self displayPlacemarks:placemarks];
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = placemark1.location.coordinate.latitude;
zoomLocation.longitude= placemark1.location.coordinate.longitude;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1000, 1000);
MKCoordinateRegion adjustedRegion = [self.mapview regionThatFits:viewRegion];
[self.mapview setRegion:adjustedRegion animated:YES];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = placemark1.location.coordinate;
pa.title = [self.sitePC valueForKey:@"siteName"];
[self.mapview addAnnotation:pa];
}
I hope this make sense .
How can I Show all the location on the map when it loads ?
Question updated since the original question was a spelling mistake
@”sitePostcode” is not the same as @”sitePostCode”. You use the former in your call to
-valueForKeyin-myMapView, but the picture of your Core Data model shows the latter.Update: To show a location on a map, you use a map annotation or overlay. For example, you can add a
MKPinAnnotationto your map to indicate a position on the map. See Annotating Maps for more information. I see that you’re already usingMKPointAnnotation, so it’s not clear what your question is. Perhaps you’re trying to show all the annotations at once — if that’s the problem, you’ll just need to calculate the rectangle that bounds all your locations and zoom the map to include that area.