Bring ios mapview in zoomed in mode during first load - ios

Hello i am doing an iOS6 in-house iPad app. On my ViewController i have a scroll view. On that at the bottom left i have a map view (20,594,360,347).Mapview location on my scroll view. I have a get location button. Brings the location correctly in zoomed in mode (it shows my office on the map clearly).Works fine. I save the record and open another one and save this record also. So i have 2 records now. Here is my problem. I open my first record and it brings the map in world view. I can see the annotation of where my office is and i zoom in... zoom in and i see my office. It doesnt bring the location directly in zoom in mode. I close this 1st record and open 2nd record it brings in the location in zoomed in mode(can see my office). I open first record now, i get zoomed in mode (i can see my office clearly). So how do i get the map view to show my first record the first time in zoomed in mode?
Summary : Opening a saved record for the first time shows the map in world view as against to zoomed in mode.
- (void)setMap:(CLLocationCoordinate2D)currentCoordinates{
....code
[self.nwMapView setMapType:MKMapTypeSatellite];
[self.nwMapView setScrollEnabled:YES];
MKCoordinateRegion extentsRegion = MKCoordinateRegionMakeWithDistance(currentCoordinates, 80, 80);
extentsRegion.span.longitudeDelta = 0.002f;
extentsRegion.span.latitudeDelta = 0.002f;
[self.nwMapView setRegion:extentsRegion animated:NO];
ITMAnnotation *annotation = [[ITMAnnotation alloc] initWithCoordinate:currentCoordinates addressDictionary:nil];
annotation.title = #"Drag to Move Pin";
annotation.subtitle = [NSString stringWithFormat:#"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
NSLog(#"subtitle change at 314");
[self.nwMapView addAnnotation:annotation];
self.tempMapView = self.nwMapView;
}
What setting should i enable to get the map in zoomed in mode.? If you need more information,please ask. Thanks.

At what point are you calling setMap? If you are doing it before viewDidLoad then you'll be losing all the set up you do to the UI because it hasn't been loaded yet. Once the VC is loaded you can setRegion on the map and do what ever. I suspect you are reusing the VC with the second record so it is calling setRegion on map that is read to be used.

Related

Mapbox iOS's flyToCamera keeps on going back to initial location unless user moves around map first

flyToCamera goes to the new camera location and then goes back to the previous camera location.
If the user moves the map (using drag gesture), even if a little bit, the flyToCamera function starts working.
This is my code:
- (void) goToSomeCity {
CLLocationCoordinate2D city = CLLocationCoordinate2DMake(34.0522,-118.2437);
MGLMapCamera *originCamera = [MGLMapCamera cameraLookingAtCenterCoordinate:city fromEyeCoordinate:self.mapView.userLocation.coordinate eyeAltitude:5000];
[self.mapView flyToCamera:originCamera completionHandler:^{
// Optionally do something
}];
}
The function is called by a button:
- (IBAction)userPressedGoToCity {
[self goToSomeCity];
}
If the user presses the button when the app starts or without moving around first (dragging the map to change the center of the map), then the function will go to the new camera and then move back to the initial location. But when the user does drag to move around the map, even if a little bit, the function works.
It sounds like you have a user tracking mode enabled, which will move the map to follow the location of the user (and disable when the user moves the map themselves).

Zoom into current user's location on MapView without restricting scrolling?

I'm using the following code to zoom into my user's current location on a MapView. It works great, however I still want to allow my users to be able to scroll outside of the set region as well (e.g. so that they can see other users on the map). Right now, if my user scrolls outside of the set region, the MapView reverts the user back inside of the set region. How can I execute the below code (zooming into the user's location) while still allowing them to scroll outside of the set region?
MapViewController.m
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 1300, 1300);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}
I wrote a short an easy app that will show the user location and also keeps track of the user location. The app will focus on the user location and will keep the user location centered as long as you don't scroll the map view.
As soon as you start scrolling the map view moves away from the user location and stays that way, since the map view is not automatically moving back. To enable you to get back to the user location, I added a button called "focus" that centers the map view back to the user location and makes the map again focus on the user location until you start scrolling away again.
The app is actually quite simple, it uses the two properties in MKMapView:
var showUserLocation: Bool {get set}
var userTrackingMode: MKUserTrackingMode {get set}
You can, of course, zoom further in to the user location by setting the region, but that is easily done with the setRegion(_:animated:).
You can find the code on Github here and download it to see how it works. You can easily test this with the simulator.
Let me know if this helps.

Not able to move map after starting navigation

hi i am using skobbler offline map in my application and everything works fine except one thing, after starting navigation i am able to rotate, zoom in, zoom out in the map but cannot move the map please help solving this. if i set follow user position to NO it works fine but i have to follow user position while in navigation. i had already tried this
Not able to move map after starting Navigation SKMAPS but i want follow user position to be YES .please help thanks in advance
[SKRoutingService sharedInstance].navigationDelegate = self;
SKNavigationSettings* navSettings = [SKNavigationSettings navigationSettings];
navSettings.navigationType=SKNavigationTypeReal;
navSettings.distanceFormat=SKDistanceFormatMilesFeet;
[[SKRoutingService sharedInstance]startNavigationWithSettings:navSettings];
self.mapView.settings.followUserPosition = YES;
self.mapView.settings.displayMode = SKMapDisplayMode2D;
I think that these 2 requirements are conflicting:
you want to be able to pan the map - this means that you should be able to move where ever you want on the map disregarding the current user position
you want to follow the user position - this means that the map should automatically recenter on the user every time the user position is updated
From my view you can switch between these 2 scenarios (see for example the "Car navigation UI" example in the skobbler/Telenav demo project - there once you start panning the map you go to 2D without following the user position and when you click the "back" button you switch back to 3D navigation following the user position) but you can't have both at the same time (as they are logically exclusive).
If I'm missing a specific use case let me know

return to apple maps at different zoom

I have a map of a zoo with pins that locate the animals. Zoom on the map. Tap on a pin then tap callout and it takes the user to a view with pic of animal and description/narrative. The "map" button on that view returns the user to the zoo map at the original zoom level. Does anyone know of a way to return to the map at the last zoom level/location?
You can set what the region of what the user can see when your map gets displayed by using the
[self.mapView setRegion:adjustedRegion animated:YES];
function. So what you want to do is, save the "region" property just when the map view is about to disappear so that you can set it again when the map view appears.

Problems with current location pin

I'm working on an app that shows a couple of places on the map along with the user's current position.
I have two small problems with it:
First off, I want the current location pin to be the default blue circle, but it shows a green pin just like the other locations.
Second problem, whenever I touch the screen, the current location pin drops again. It just can't seem to be steady like the other ones. It's like it's being called whenever I interact with the app.
Make sure you set your mapView delegate to self...that should fix the pin color. Not sure about your other problem
// in the viewDidLoad
[mapView setDelegate:self];
where "mapView" is defined as "IBOutlet MKMapView *mapView;"

Resources