2016-04-04 8 views
0

私は、以下のコードを使用してcurrentLocationを見つけるためにMapkitの作業を行いました。現在、私は現在の位置アドレスを注釈痛みに表示したいと思います。現在の位置アドレスを表示するためにジオコーディング方法を調整するにはどうすればいいですか?緯度と経度の値は?現在の住所を見つける方法は?

#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 

答えて

0

地図上の表示現在の位置のためにこれを使用..

MKPointAnnotation *annonation = [[MKPointAnnotation alloc]init]; 
CLLocationCoordinate2D mycordinate; 
mycordinate.latitude = [self.strlog floatValue]; 
mycordinate.longitude =[self.strlat floatValue]; 
annonation.coordinate = mycordinate; 
[self.mapview addAnnotation:annonation]; 
関連する問題