MKMapView one finger zoom in and out - ios

Google Maps has had this for a while (double tap then hold and slide finger up or down to zoom in or out) but Apple is just adding it to their Apple Maps app in iOS 11.
It does not seem like they are going to add this to MKMapView, at least not in the current betas.
If Apple does not give MKMapView this functionality how would I do this using gestures? Has anyone else done this?

This will help you to zoom out to world-view.
// step.1 create co-ordianate-span as follows
MKCoordinateSpan span = {.latitudeDelta = 180, .longitudeDelta = 360};
// step.2 crate region as follows
MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(0.0000f, 0.0000f), span);
// step.3 zoom using region to map as follows
[self.mapView setRegion:region animated:YES];

Related

iOS MKMapView programmatically zoom via setRegion has bugs when UserTrackingMode is follow and map is rotated

I try write programmatically zoom based on setRegion method
func zoomMap(byFactor delta: Double) {
var region: MKCoordinateRegion = self.mapView.region
var span: MKCoordinateSpan = mapView.region.span
span.latitudeDelta *= delta
span.longitudeDelta *= delta
region.span = span
mapView.setRegion(region, animated: true)
}
I find two problems with it.
First problem
when map is rotated, setRegion return map to north
I resolve it via camera.altitude method
Second problem
when mapView userTrackingMode property is follow and I programmatically zoom it after some seconds map returns its zooming state in default follow zooming. Approach "disable userTrackingMode -> zoom -> enable userTrackingMode" does not help.
When I zoom map via UI gesture userTrackingMode.follow works normally. Is it iOS MKMapView bug?
Tested in iOS 10.

Different views in Apple maps and MKMapview for same place

Hi I have integrated MKMapView map in my iOS application. Apple maps show different view for one place and MKMapview shows different view for same place. How can I get clear view with zoom level like Apple maps.
This is the Apple maps view screenshot link
This is the MKMapView map screenshot link
it's look like the same place. But issue it you map has less zoom level.
Reduce you span value to make it more zoom. So you will get the same result. Try to solve by error and trial. you can check the below code to set span value of the map.
MKCoordinateSpan span;
span.latitudeDelta = 0.4;
span.longitudeDelta = 0.4;
MKCoordinateRegion region;
region.center = newLocation.coordinate;
region.span = span;
[mapView setRegion:region animated:NO];

Allow user to zoom in but not out on mapview region - iOS Objective-C

When my mapView is loaded, I set the mapRegion to the following:
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 700, 700);
[self.mapView setRegion:region];
I want the user to be able to zoom in on the region, but not zoom out past it.
What is the best way of going about doing this?
Unfortunately, MKMapViews are a bit limited but this solution might help you out.
iOS - How to limit the MapView to a specific region?

How to zoom into user current location?

I wanna zoom into the user current location when the app starts in the MapKit.
This is my code (in the viewDidLoad function):
Locate=[[CLLocationManager alloc]init];
Locate.delegate=self;
Locate.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
Locate.distanceFilter=kCLDistanceFilterNone;
[Locate startUpdatingLocation];
[super viewDidLoad];
//Region
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;
//Span
MKCoordinateSpan span;
span.latitudeDelta=0.3f;
span.longitudeDelta=0.3f;
//Set Region
myRegion.center=center;
myRegion.span=span;
[_MyMap setRegion:myRegion animated:YES];
Also I implemented the didUpdateLocation function with the same code as previous.
The problem is that when the user location is changing (when the user is moving) the screen makes zoom at him but I can't move the screen, if I try to move it return to the user location immediately, so I can't see the whole map.
For Zooming the map you have to change the region values means center and span.once see this one Mapview Zoom
in my case i have used this one for moving the map when i click on particular button.
MKCoordinateSpan span = MKCoordinateSpanMake(30.5982f,0.0001f);
CLLocationCoordinate2D coordinate = {36, 90};
MKCoordinateRegion region = {coordinate, span};
MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
[self.mapView setRegion:regionThatFits animated:YES];
I solved this issue by adding touchesMoved function and I stopped updating the Location in this function.
Solved.

MKMapView reset back to world view

How do I reset an MKMapView back to the world view zoom level?
The map rect for the world is stored as a constant named MKMapRectWorld.
MKCoordinateRegion worldRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
map.region = worldRegion;
One other way is to set the zoom level of the map. Although the MapKit framework does not support zoom levels as Google Maps API does, you can use this category extension written by Troy Brant.
Set the center coordinate to 0, 0 with zoom level 0 to get the same result.
[map setCenterCoordinate:CLLocationCoordinate2DMake(0, 0) zoomLevel:0 animated:0];
Try this:
MKCoordinateRegion region = MKCoordinateRegionMake(mapView.centerCoordinate, MKCoordinateSpanMake(180, 360));
[mapView setRegion:region animated:YES];
This will set a new region for the map view using the current center coordinate, and the maximum possible span (180 degrees of latitude, 360 degrees of longitude).
For those hoping to do this in Swift:
let region = MKCoordinateRegion(.world)
mapView.setRegion(region, animated: true)
MKMapView can not zoom out to show the whole world. No matter what you are using, MKMapRectWorld, zoom level 0, or MKCoordinateSpanMake(180, 360).

Resources