0

ユーザーの正確な現在の住所(国、州、市)を取得する必要があります。そこで、緯度と経度を見つけて、逆ジオコーディングを使って調べましたが、緯度と経度自体を取得することはできません。xcode4.1を使用して、iPhoneシミュレーターでテストしています。

これは私が取り組んでいるコードです:

- (void)viewDidLoad
{
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    [locationManager startUpdatingLocation];
    NSLog(@"%@", [self deviceLocation]);
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    int degrees = newLocation.coordinate.latitude;
    double decimal = fabs(newLocation.coordinate.latitude - degrees);
    int minutes = decimal * 60;
    double seconds = decimal * 3600 - minutes * 60;
    NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                     degrees, minutes, seconds];
    latLabel.text = lat;
    degrees = newLocation.coordinate.longitude;
    decimal = fabs(newLocation.coordinate.longitude - degrees);
    minutes = decimal * 60;
    seconds = decimal * 3600 - minutes * 60;
    NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                       degrees, minutes, seconds];
    longLabel.text = longt;
}

緯度と経度を見つけてユーザーの住所を見つけるにはどうすればよいですか?

編集:

私のバージョンをXcode4.5に更新しました。しかし、それでも場所を見ることができませんでした....?Yそうですか?

4

2 に答える 2

0

変化 :

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

これで、緯度と経度はfloatnotとして取得されintます。

CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];

float longitude=coordinate.longitude;
float latitude=coordinate.latitude;

を使用して、緯度と経度でユーザーの住所を検索しますCLGeocoder

編集このリンクを参照してください。

于 2012-11-17T06:55:02.567 に答える
0

このファイルをダウンロードしてください

添付した zip ファイルには、次の 4 つのファイルがあります。

LocationGetter.h および .m

PhysicalLocation.h および .m

インポートするだけです

#import "PhysicalLocation.h"

 PhysicalLocation *physicalLocation = [[PhysicalLocation alloc] init];
    [physicalLocation getPhysicalLocation];

クラスgetPhysicalLocationで_PhysicalLocation.m

#pragma mark MKReverseGeocoder Delegate Methods
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

    NSLog(@"%@",placemark);

    objcntrAppDelegate = (yourappDeleger *)[[UIApplication sharedApplication]delegate];

    objcntrAppDelegate.strCountry=placemark.country;
    objcntrAppDelegate.strSuburb=placemark.subAdministrativeArea;


    [[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedAddress" object:nil userInfo:nil];


     [geocoder autorelease];
}

緯度、経度、現在の都市、国など、必要なものはすべて揃っています。お役に立てば幸いです。 注:-シミュレーターの結果が正しくないため、デバイスでテストする必要があります。

アップデート

更新されたDEMO

于 2012-11-17T07:02:05.493 に答える