我是iphone MapView的新用户,当用户移动地图时我需要获取iphone中可见区域的纬度和经度
答案 0 :(得分:3)
您可以使用MKMapView的属性获取地图中心点的坐标:
centerCoordinate.latitude
和centerCoordinate.longitude
。
例如:
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(
map.centerCoordinate.latitude, map.centerCoordinate.longitude);
这就是你所说的经纬度和经度“我需要用户移动地图时的纬度和经度”?
希望这会有所帮助......
答案 1 :(得分:1)
使用MKMapView的.region属性。
MKMapView *myMapView = [[MKMapView alloc] initWithFrame:...];
MKCoordinateRegion region = myMapView.region;
// Center of the screen as lat/long
// region.center.latitude
// region.center.longitude
// width and height of viewing area as lat/long
// region.span.latitudeDelta
// region.span.longitudeDelta
最高
答案 2 :(得分:1)
在Appdelegate.h
CLLocationManager *locationManager;
然后在Appdelegate.m (didFinishLaunchingWithOptions)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
当您使用设备移动时,这将调用方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *currentLocation = [locations lastObject];
NSString *latitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.longitude];
NSMutableArray *temp = [[NSMutableArray alloc] initWithCapacity:0];
[temp addObject:latitude];
[temp addObject:longitude];
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:temp forKey:@"CLocation"];
[temp release];
}
从中使用。