i'am new to iphone MapView,when user moves the Map i need to get latitude and longitude of the visible region in iphone
问问题
2550 次
3 回答
3
centerCoordinate.latitude
您可以使用 MKMapView :和的属性获取地图中心点的坐标
centerCoordinate.longitude
。
例如 :
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(
map.centerCoordinate.latitude, map.centerCoordinate.longitude);
这就是您所说的“用户移动地图时我需要纬度和经度”的纬度和经度?
希望这会有所帮助……</p>
于 2013-05-11T09:21:43.463 回答
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];
}
从此使用。
于 2013-05-11T06:16:51.513 回答
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
最大限度
于 2013-05-11T05:10:50.193 回答