Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,216
1,030
I am trying to find the center of visible region using MapKit.

Code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
	location=newLocation.coordinate;
	//One location is obtained.. just zoom to that location
	
	NSLog(@"%@",oldLocation);
	
	if (!oldLocation) {
		
		MKCoordinateRegion region;
		region.center=location;
		//Set Zoom level using Span
		MKCoordinateSpan span;
		span.latitudeDelta=1.5;
		span.longitudeDelta=1.5;
		region.span=span;
		
		NSLog(@"center = %f",newLocation.coordinate);
		
		[mapView setRegion:region animated:TRUE];
		
	}
	
}

That returns the proper center. Unforunately, I can't figure out what to do in - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

I tried doing
Code:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
	NSLog(@"Scrolling");
	MKCoordinateRegion region;
	region.center = location;
	NSLog(@"center = %f, %f",location.latitude, location.longitude);

}

This only shows the current location of the device, not the center of the map. Any help would be appreciated.
 
Mission sucessful!

Code:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
     MKCoordinateRegion region;
     centerCoordinate=mapView.region.center;
     region.center= centerCoordinate;
	
     NSLog(@"%f,%f",centerCoordinate.latitude, centerCoordinate.longitude);
}
 
Mission Completed !

Code:
- (void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated {
    MKCoordinateRegion region;
    [B]CLLocationCoordinate2D[/B] centerCoordinate;
    
    centerCoordinate=mapView1.region.center;
    region.center= centerCoordinate;
	
    NSLog(@" %f,%f",centerCoordinate.latitude, centerCoordinate.longitude);
}
 
Last edited by a moderator:
Code:
- (void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated {
    MKCoordinateRegion region;
    [B]CLLocationCoordinate2D[/B] centerCoordinate;
    
    centerCoordinate=mapView1.region.center;
    region.center= centerCoordinate;
	
    NSLog(@" %f,%f",centerCoordinate.latitude, centerCoordinate.longitude);
}

This is a three-and-a-half-year-old post, and you posted the same code that the OP posted himself. Why resurrect such an old thread, especially when you don't have anything meaningful to add?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.