2016-04-04 18 views
0

Aşağıdaki kodu kullanarak currentLocation öğesini bulmak için Mapkit'te görev yaptım. Şimdi mevcut konum adresini ek açıklama ağrısında görüntülemek istiyorum. Geçerli konum adresi, konum ve boylam değerlerini görüntülemek için coğrafi kodlama yöntemini mi?Geçerli konumun adresi nasıl bulunur?

#import "MapKitViewController.h" 
    #import "ViewController.h" 
    #define METERS_MILE 1609.344 
    #define METERS_FEET 3.28084 

@interface MapKitViewController()<CLLocationManagerDelegate,MKMapViewDelegate > 

@end 

@implementation MapKitViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
// _mapView.delegate = self; 


    locationManager =[[CLLocationManager alloc] init]; 

    [[self mapView ] setShowsUserLocation:YES]; 
    [locationManager setDelegate:self]; 
    [locationManager requestWhenInUseAuthorization]; 
    [locationManager requestAlwaysAuthorization]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager startUpdatingLocation]; 
    NSLog(@" startUpdatingLocation"); 


} 

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray<CLLocation *> *)locations{ 
    CLLocation *location=locations.lastObject; 
    [[self latitudeValue] setText:[NSString stringWithFormat:@"%.6f",location.coordinate.latitude]]; 
    [[self longnitudeValue] setText:[NSString stringWithFormat:@"%.6f",location.coordinate.longitude]]; 
// [[self altitudeValue] setText:[NSString stringWithFormat:@"%.2f feet",location.altitude*METERS_FEET]]; 
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 2*METERS_MILE, 2*METERS_MILE); 
    [[self mapView] setRegion:viewRegion animated:YES]; 
    MKPointAnnotation *point=[[MKPointAnnotation alloc]init]; 
    point.coordinate=location.coordinate; 

    [self.mapView addAnnotation:point]; 

    [email protected]"this is my place"; 


    NSLog(@"I got the point"); 




    NSLog(@"didUpdateLocations"); 


} 
- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

/* 
#pragma mark - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} 
*/ 


@end 

cevap

0

harita üzerinde görüntüleme Mevcut konum için bunu kullanın ..

MKPointAnnotation *annonation = [[MKPointAnnotation alloc]init]; 
CLLocationCoordinate2D mycordinate; 
mycordinate.latitude = [self.strlog floatValue]; 
mycordinate.longitude =[self.strlat floatValue]; 
annonation.coordinate = mycordinate; 
[self.mapview addAnnotation:annonation]; 
İlgili konular