Convert coordinates to City name?

后端 未结 9 1200
Happy的楠姐
Happy的楠姐 2020-12-02 07:41

How to get an address from coordinates using MapKit?

I have this code when long press on the map it gets the coordinates:

func didLongPressMap(sender         


        
9条回答
  •  猫巷女王i
    2020-12-02 08:23

    In didUpdateToLocation method:

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:
        (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
        CLLocation *location = [locationManager location];
    
    
        CLLocationCoordinate2D coordinate = [location coordinate];
    
    
        latitude = [NSString stringWithFormat:@"%.12f", coordinate.latitude];
        longitude = [NSString stringWithFormat:@"%.12f", coordinate.longitude];
    
        CLLocation *location1 = [[CLLocation alloc]
                                 initWithLatitude:latitude.floatValue
                                 longitude:longitude.floatValue];
    
        self.myGeocoder = [[CLGeocoder alloc] init];
    
        [self.myGeocoder
         reverseGeocodeLocation:location1
         completionHandler:^(NSArray *placemarks, NSError *error) {
            if (error == nil &&
                 [placemarks count] > 0){
                placemark = [placemarks lastObject];
                NSString*    vendorLocation=[NSString stringWithFormat:@"%@ %@",
                                              placemark.locality,
                                              placemark.subLocality];
                NSLog(@"%@",vendorLocation);
            }
        }];
    }
    

提交回复
热议问题