iOS開発初心者です。緯度と経度の値があります。緯度と経度を使用して場所の名前を取得したいですか? iOSで可能ですか?
4 に答える
はい、その可能性は逆ジオコーディングと呼ばれます。最初にフレームワークをインポートしてから、iOS5(およびCoreLocation
それ以降)で使用する必要があります。CLGeocoder
iOS4以下の場合mkreversegeocoder
。`CLGeocoderを使用して住所を取得する方法は次のとおりです。場所オブジェクトをフィードするだけで、残りは実行されます。
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
//Print the location to console
NSLog(@"I am currently at %@",locatedAt);
}];
取得する配列はオブジェクトのplacemarks
インスタンスです。CLPlacemark
ITはあなたにアクセスを提供します-
Accessing the Placemark Attributes
name property
addressDictionary property
ISOcountryCode property
country property
postalCode property
administrativeArea property
subAdministrativeArea property
locality property
subLocality property
thoroughfare property
subThoroughfare property
region property
もう 1 つの簡単な方法は、Google マップ REST API を使用することです。次の URL に対して Web サービス呼び出しを行うと、場所の詳細を含む json が返されます。
http://maps.googleapis.com/maps/api/geocode/json?latlng=10.03,10.03&sensor=false
はい。CLGeocoder
iOS5以降でご利用いただけます。
MKReverseGeocoder
以前のOSバージョンをサポートする必要がある場合に使用できます。
MKReverseGeocoder 以外では、google api を使用することをお勧めします。アプリで使用していますが、クラッシュはなく、応答も迅速です。