我想从MapKit for iPhone中的坐标值获取位置名称
发布时间:2020-12-15 01:57:23 所属栏目:百科 来源:网络整理
导读:我想从坐标值中获取位置名称。这里是代码, - (void)viewWillAppear:(BOOL)animated { CLLocationCoordinate2D zoomLocation; zoomLocation.latitude = 39.281516; zoomLocation.longitude= -76.580806; MKCoordinateRegion viewRegion = MKCoordinateRegion
我想从坐标值中获取位置名称。这里是代码,
- (void)viewWillAppear:(BOOL)animated { CLLocationCoordinate2D zoomLocation; zoomLocation.latitude = 39.281516; zoomLocation.longitude= -76.580806; MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation,0.5*METERS_PER_MILE,0.5*METERS_PER_MILE); MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion]; [_mapView setRegion:adjustedRegion animated:YES]; } 所以,从那个纬度和经度我想知道那个位置的名字。 解决方法
以下代码在ios5及以上版本中工作
CLGeocoder *ceo = [[CLGeocoder alloc]init]; CLLocation *loc = [[CLLocation alloc]initWithLatitude:32.00 longitude:21.322]; //insert your coordinates [ceo reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks,NSError *error) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; if (placemark) { NSLog(@"placemark %@",placemark); //String to hold address NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@","]; NSLog(@"addressDictionary %@",placemark.addressDictionary); NSLog(@"placemark %@",placemark.region); NSLog(@"placemark %@",placemark.country); // Give Country Name NSLog(@"placemark %@",placemark.locality); // Extract the city name NSLog(@"location %@",placemark.name); NSLog(@"location %@",placemark.ocean); NSLog(@"location %@",placemark.postalCode); NSLog(@"location %@",placemark.subLocality); NSLog(@"location %@",placemark.location); //Print the location to console NSLog(@"I am currently at %@",locatedAt); } else { NSLog(@"Could not locate"); } } ]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |