MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance(annotation.coordinate, 10, 10);
[self.mapView setRegion:region];
This is my code but it doesn't work correctly.
I have a map with my current location and some annotations.
Now I want to show only the annotations which are in a radius of 10 meters.
Is there a minimum radius? If I take 1000m it works correctly!
Related
Please check the below Image. How to Avoid this type of zoom level in iPhone
Now getting Result:
Expected Result:
I don't think there is a way of telling if satellite images would be available at zoom level for given region. Better approach is to set your MKMapView to MKMapTypeStandard and give the user the option of switching to MKMapTypeSatellite in this case you will always have a map details to display on initial presentation of your MKMapView object
You can set the zoom by using MKCoordinateRegion and setting its span latitude & longitude delta as:
MKCoordinateRegion region;
region.center.latitude = {desired lat};
region.center.longitude = {desired lng};
region.span.latitudeDelta = 1;
region.span.longitudeDelta = 1;
region = [mapView regionThatFits:region];
[mapView setRegion:region animated:TRUE];
Vary the span.longitudeDelta and span.latitudeDelta to get the required zoom.
i am adding MKCircleView to the user annotation like so :
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (!_MapCentered) {
**_circle = [MKCircle circleWithCenterCoordinate:userLocation.coordinate radius:3000];
[_map_view addOverlay:_circle];**
_MapCentered = YES;
}
}
it will fire once and once the user location has traced, it works well but as you can see the diameter of the circle view is 3000 meters. so now i want the zoom level to fit the CircleView like so :
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(mapView.userLocation.coordinate, 0.270, 0.270);
[_map_view setRegion:viewRegion animated:YES];
i have changed the delta degrees to other numbers but nothing is changed.
how can i manage this?
The distance parameters in the MKCoordinateRegionMakeWithDistance function are in meters (not degrees).
Also, the meters specify the full width and height so you have to use double the value of the circle's radius.
So it should be:
MKCoordinateRegion viewRegion =
MKCoordinateRegionMakeWithDistance
(mapView.userLocation.coordinate, 6000, 6000);
You could also just set the map view's visibleMapRect to the boundingMapRect of the circle overlay so you don't have to repeat the distance values:
mapView.visibleMapRect = _circle.boundingMapRect;
You need to set your span.
so set your span value in longitudeDelta & latitudeDelta
yourRegion.span.longitudeDelta = 0.004; // set required zoom value
yourRegion.span.latitudeDelta = 0.004; // set required zoom value
For Google's zoom level i use this category for MKMapView
Otherwise use Anna's solution
I am using following codes
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04), Some KM, Some KM);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];
[self.mapView setRegion:adjustedRegion animated:YES];
Otherway around is
MKCoordinateRegionMake(CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04), ADD SPAN HERE)
Both of these makes the map zoom. How is it possible that I change the Region without any zoom.
Get the current region and just change the center point.
// get current region
MKCoordinateRegion region = self.mapView.region;
// Update the center
region.center = CLLocationCoordinate2DMake(annView.annotation.coordinate.latitude, annView.annotation.coordinate.longitude - .04);
// apply the new region
self.mapView.region = region;
If you have a coordinate to set, use the MKMapView -setCenterCoordinate:animated: method. Animating the position change gives the user a clue about what's happened.
CLLocationCoordinate2D coordinate = annView.annotation.coordinate;
[myMapView setCenterCoordinate:coordinate animated:YES];
Also, no need to make a new coordinate, just use the one already in the annotation view.
I'm using an MKMapView and I'm initializing like this:
homeLocation.latitude = 42.033126;
homeLocation.longitude = -70.168621;
[self.mapView setCenterCoordinate:homeLocation animated:NO];
MKCoordinateRegion viewRegion;
viewRegion.center = homeLocation;
viewRegion.span = MKCoordinateSpanMake(1.7, 1.7);
[self.mapView setRegion:[self.mapView regionThatFits:viewRegion] animated:NO];
and here is my app
That's fine, except for my app I need to have it zoomed out a tiny bit more. But when I try this:
viewRegion.span = MKCoordinateSpanMake(1.8, 1.8); // use span of 1.8, not 1.7
I get this:
It is zoomed way out. If I look at the MKMapView's region the latitudeDelta i 3.54981 and the longitudeDelta is 3.51562.
How can I set my span to a value between 1.7 and 3.5? I'd love to hit around 2.25 for this particular application.
NOTE: the mapview pinch zooms just fine to whatever span I want.
MKCoordinateSpanMake uses degrees, and 1 degree is about 69 miles. If you want a more fine grained setting, use MKCoordinateRegionMakeWithDistance instead.
CLLocationCoordinate2D homeLocation;
homeLocation.latitude = 42.033126;
homeLocation.longitude = -70.168621;
[self.mapView setCenterCoordinate:homeLocation animated:NO];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance( homeLocation, 200000, 200000);
// 200000 meter is approximately 1.8 degree
[self.mapView setRegion:[self.mapView regionThatFits:viewRegion] animated:NO];
Have you tried on the device? Sometimes I have more control on the zoom level on the device than on the simulator.
Hi have MKMapView and I make it to zoom depending on the annotations added to mapview, but sometimes I see map zoomed to some level in which annotations fall on the edges and half visible. Below is the code i'm using to set the map region.
MKPolygon *poly = [MKPolygon polygonWithCoordinates:points count:annotationCount];
MKCoordinateRegion region=MKCoordinateRegionForMapRect([poly boundingMapRect]);
Please provide some solution, Thanks.
So your region is too small, have you considered making it bigger?
Your MKCoordinateRegion has a CLLocationCoordinate2D (center) and a MKCoordinateSpan (span). That MKCoordinateSpan has a latitudeDelta (consider this the height) and a longitudeDelta (consider this the width). What you want to do is a make a slightly larger region. So my first guess is
region.span.latitudeDelta = region.span.latitudeDelta * 1.01;
Then set your mapview to that region