2017-05-30 8 views
0

コードはこちらです。 これは基本的には機能しますが、私は道を紛失してしまい、[geocoder]ルーチンから "point.title"を戻す方法を理解することができません。 point.titleはMapkitアノテーションの一部です。私はコメントアウトされているので、単純な文字列をpoint.titleに入れることができますが、私がそれを行うことができないのは、完全な 'locatedAT'または実際にplacemark.subLocalityのどれかを返すことです。アイテム。locateAtジオコードを取得できません。座標の位置はルーチンから返されます

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { 

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800); 
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES]; 

// Add an annotation 
MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; 
point.coordinate = userLocation.coordinate; 
//point.title = @"Where am I?"; 
//point.subtitle = @"I'm here!!!"; 
//////////////////////// 
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
CLLocation *loc = [[CLLocation alloc]initWithLatitude:userLocation.coordinate.latitude longitude:userLocation.coordinate.longitude]; 

[geocoder reverseGeocodeLocation: loc 
       completionHandler:^(NSArray* placemarks, NSError* error){ 
        CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
        if (placemark) { 

         // NSLog(@"placemark %@",placemark); 
         //String to hold address 
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; 
         // NSLog(@"addressDictionary %@", placemark.addressDictionary); 

        // NSLog(@"placemark %@",placemark.region); 
        // NSLog(@"placemark %@",placemark.country); // Give Country Name 
        // NSLog(@"placemark %@",placemark.locality); // Extract the city name 

        // NSLog(@"location %@",placemark.name); 
        // NSLog(@"location %@",placemark.ocean); 
        // NSLog(@"location %@",placemark.postalCode); 
        // NSLog(@"location %@",placemark.subLocality); 

         //Print the location to console 
        // NSLog(@"I am currently at %@",locatedAt); 

         point.title = locatedAt; 

        } 
        else { 
         NSLog(@"Could not locate"); 
        } 
} 
]; 
/////////////////////////// 

NSLog(@"point.title %@",point.title); 

[self.mapView addAnnotation:point]; 
[self.mapView selectAnnotation:point animated:YES]; } 
+0

ここにはどのようなエラーや問題があるのですか教えてください。 –

+0

逆ジオコーディングから何を得たいですか? –

+0

私は、locatedAt文字列をpoint.titleまたはpoint.subtitle変数に入れようとしています。ジオコーダー・ルーチンで生成されます。 – Postmaster

答えて

0

次のコードを追加/変更するだけでコードを取得できました。 point.title = locatedAtが最後のポイントを上書きするため、なぜ動作するのかわかりません.title = @ "ここにいます";それは中括弧の外側です。なぜなら2つのpoint.titleとpoint.sustitle行を取り除くと、ピンの実際のジオロケーションが出力されなくなるからです。

     //Print the location to console 
         //NSLog(@"I am currently at %@",locatedAt); 


         point.title = locatedAt; 

        } 
        else { 
         NSLog(@"Could not locate"); 
        } 

    } 
]; 
point.title = @"Where am I"; 
    // NSLog(@"point.title %@",point.title); 
point.subtitle = @"I'm here!!!"; 

[self.mapView addAnnotation:point]; 
[self.mapView selectAnnotation:point animated:YES]; } 
関連する問題