-3

我需要使用纬度和经度查找用户位置的名称。我使用以下代码使用注释将点固定在位置中。

//MAP VIEW Point

MKCoordinateRegion myRegion;

//Center
CLLocationCoordinate2D center;
center.latitude=latitude;
center.longitude=longitude;

//Span
MKCoordinateSpan span;
span.latitudeDelta=THE_SPAN;
span.longitudeDelta=THE_SPAN;

myRegion.center=center;
myRegion.span=span;

//Set our mapView
[MapViewC setRegion:myRegion animated:YES];

//Annotation

//1.create coordinate for use with the annotation
CLLocationCoordinate2D wimbLocation;
wimbLocation.latitude=latitude;
wimbLocation.longitude=longitude;

Annotation * myAnnotation= [Annotation alloc];
myAnnotation.coordinate=wimbLocation;
4

2 回答 2

0

First You need to import the AddressBook/AddressBook.h Then include the below method

-(NSString*)locationFromCoordinate:(CLLocationCoordinate2D)coordinate
{
     CLGeocoder *geocoder = [[CLGeocoder alloc] init];

     CLLocation *loc = [[CLLocation alloc]initWithLatitude:coordinate.latitude
                                                    longitude:coordinate.longitude];
     NSString *address;
     [geocoder reverseGeocodeLocation:loc
               completionHandler:^(NSArray *placemarks, NSError *error) {

                   if (error) {
                       NSLog(@"Failed with error: %@", error);
                       return;
                   }

                   if (placemarks.count > 0)
                   {
                       CLPlacemark *placemark = placemarks[0];

                       NSDictionary *addressDictionary =
                       placemark.addressDictionary;

                       address = [addressDictionary
                                            objectForKey:(NSString *)kABPersonAddressStreetKey];

                   }

      return address;
}
于 2013-11-12T05:25:31.933 回答
0

这可能是最简单的方法

- (void)reverseGeocodeLocation {
      CLLocation *someLocation=[[CLLocation alloc]initWithLatitude:20.256456 longitude:68.545656]
  CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  [geocoder reverseGeocodeLocation:someLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    if(placemarks.count){
      NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary];
      [self.addressOutlet setText:[dictionary valueForKey:@"Street"]];
      [self.cityOutlet setText:[dictionary valueForKey:@"City"]];
      [self.stateOutlet setText:[dictionary valueForKey:@"State"]];
      [self.zipOutlet setText:[dictionary valueForKey:@"ZIP"]];
    }
  }];

}
于 2013-11-12T05:23:52.117 回答