iOS根据输入的位置获取经纬度

NSString *oreillyAddress = @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA" //测试使用中文也可以找到经纬度具体的可以多尝试看看~

CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];

[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {

    if ([placemarks count] > 0 && error == nil)

    {

        NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]);

        CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];

        NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);

        NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);

    }

    else if ([placemarks count] == 0 && error == nil)

    {

        NSLog(@"Found no placemarks.");

    }

    else if (error != nil)

    {

        NSLog(@"An error occurred = %@", error);

    }

}];

你可能感兴趣的:(ios,地图,IOS功能笔记)