我有問題得到這個工作,用核心數據,來獲取用戶的名單我,核心數據和CLGeocoder
NSFetchrequets額外的用戶位置,地方名單和郵編
NSFetchRequest *request =[NSFetchRequest fetchRequestWithEntityName:@"SiteLocation"]; //request all objects
NSArray *fetchedObjects = [self.srmDatabase.managedObjectContext executeFetchRequest:request error:nil];
所以我有一個實體 「SITELOCATION」 裝載的tableview與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;
}
然後我把選擇列上的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";
})
在此的MapViewController將sitePostcode轉換爲標
-(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];
}
我希望這是有意義的。
如何在加載時顯示地圖上的所有位置?
問題,因爲原來的問題是更新一個拼寫錯誤
Haaaaaaaaaaaaa兩天在這工作... 30分鐘寫這個問題都浪費了..... aaaa謝謝,我可以問別的東西.. – HernandoZ
問題編輯 - 如何顯示地圖上的所有位置,當它加載。 – HernandoZ
我會更新我的答案,但是最好創建一個單獨的問題,而不是完全改變現有問題的焦點。 – Caleb