Hey Freunde, ich werde den Code implementieren, um aktuelle Adresse zu bekommen.aber Problem ist, ich werde nicht bekommen perfekte Lage, sondern einige andere in der Nähe Lage so pls lösen mein Problemich bekomme keine perfekte Adresse in der Bezeichnung mit Location Manager Methode
map.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *lbl_lat;
@property (weak, nonatomic) IBOutlet UILabel *lbl_long;
@property (weak, nonatomic) IBOutlet UILabel *lbl_address;
- (IBAction)location:(id)sender;
@end
map.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
{
CLLocationManager *locationManager;
CLGeocoder *geocoder;
CLPlacemark *placemark;
}
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)location:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 500;
[locationManager startUpdatingLocation];}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
self.lbl_long.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
self.lbl_lat.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
// Reverse Geocoding
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
self.lbl_address.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
placemark.subThoroughfare, placemark.thoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
}
dank im Voraus
Ich werde versuchen, aber nicht lösen Problem – iOS