Mkmapview Show Incorrectly Saved Region

Restore MKMapView visible state/region properly

Hmm. If I understand your question correctly, you're saving the MKMapView's region (that is, its center and span), and would like to use these values to restore the map's center and zoom level, independently of whether the user rotates the device between sessions.

Have you tried calculating the width-to-height ratio of your map rectangle, and then multiplying out the changes to the span? That is, if your map has bounds of size 800 x 600 in landscape mode, then you'd multiply the longitudeDelta by 600/800 (0.75) and the latitudeDelta by 800/600 (1.33) to get the appropriate span for a 600 x 800 rectangle in portrait mode.

iPhone MKMapView: set map region to show all pins on map

To show double value in NSLog(), you should use %f, instead of %d
Change NSLog() part like this:

NSLog(@"center long: %f, center lat: %f", center_long, center_lat);
NSLog(@"max_long: %f, min_long: %f, max_lat: %f, min_lat: %f", max_long, min_long, max_lat, min_lat);

Also, using region from MKMapView is much simpler than making your own. Once it's set with zoom ratio, all you need is to dynamically move around the map with different coordinates.

MKCoordinateRegion region = self.mapView.region;
region.center = centerCoordinate;
region.span.longitudeDelta /= ratioZoomMax; // Bigger the value, closer the map view
region.span.latitudeDelta /= ratioZoomMax;
[self.mapView setRegion:region animated:YES]; // Choose if you want animate or not

How to show my current position and region onto my MKMapView with using blue dots ?

MAPKIT

First allow your map to show your current location.

 _mapView.showsUserLocation   =   YES; // This will show the blue dot on map at your current location.

Now Set the Region to zoom on your current location.

MKCoordinateRegion region;
region.center.latitude = _mapView.userLocation.coordinate.latitude;;
region.center.longitude = _mapView.userLocation.coordinate.longitude;;

region.span.latitudeDelta = 0.001;
region.span.longitudeDelta = 0.001;

MKCoordinateRegion scaledRegion = [_mapView regionThatFits:region];
[_mapView setRegion:scaledRegion animated:NO];

Make Sure to set the Region after your location is visible over map or your map is completly loaded. You can make use to delegates..

- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;

If you want to manage the UserLocation by userself..
You can use CLLocationManager class Initialize it and Use it's Delegate to get the updates on User's Current location.

CLLocationManager *locationManager  =           [[CLLocationManager alloc]init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.pausesLocationUpdatesAutomatically = NO;
[locationManager setDelegate:self];

// Delegate

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// Use New Location to show your custom marker or do any thing you want.
}

For Debugging in Simulator you set the GPS location
Go to Simulator option DEBUG-->LOCATION .. You can add custom location or can chose from the available ones.

Hope this will help you. :)



Related Topics



Leave a reply



Submit