Detect whether map has been scrolled or not in mapview - iphone

How can I detect whether map has been scrolled or not in mkmapview in ios. The delegate method of map is not getting called. please help..

Use
-(void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated
Also make sure your mapView.delegate = self;

Related

MKMapView setRegion:Animated: work on simulator but not on device iOS6

I have an MKMapView. To change the displayed region I use
[self.mapView setRegion:region animated:YES];
The strange is that on simulator the region is changed with animation, but on device the change is immediate and not animated.
I change the region after a long tap on the map...
This behavior drive me crazy and I can't able to solve it...
Thanks...
You need to slow down setRegion by using the following code
[self performSelector:#selector(setMapRegion) withObject:nil afterDelay:3.0];
-(void) setMapRegion
{
[self.mapView setRegion:region animated:YES];
}
If you load the map on device and iOS 6+ you'll experience a bit of delay till the tiles are loaded so the best thing to do is to try delaying the region change.
The map is not responsive even you set the animation it won't appear that clearly to you,it would look like it's not making any animation.
MKMapView calls its delegate method mapViewDidFinishLoadingMap: once the map has loaded all the necessary tiles and is ready to use. You should call setRegion:animated: there.

MKMapKit get visible annotationviews

How can I get all the visible MKAnnotationViews in
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)clickedview
Basically I want to make some calculation to get all the views touching (in cascade) the clickedview
thanks
You can use annotationsInMapRect: to get all the annotations inside a map rect. visibleMapRect will get you the current map rect to use.

iphone Detect selected MKPinAnnotation in a MapView

I have a custom MKPinAnnotation in which I have added a couple of peroperties , like the Id of the object and the type. What I want is when someone selects a pin in the MapView to detect which pin is selected and get that data.
And Show a button on its view to use that data in the button's action.
Can anyone help with this? I can't find how to detect if (and which) an annotation is selected.
There is already a built in method to take care of this situation for you. You need to use the method below. The view.annotation is the annotation that was tapped.
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"The annotation tapped is: %#", view.annotation.title);
}
Edit: It can be found here, the API is your friend.
https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/doc/uid/TP40008204

iOS how to keep current location center all the time

My map shows current location with blue dot..
Of course, when I move, blue dot moves.. I just want to keep blue dot center of the map all the time, making map's moving instead like Google map navigator..
I searched a lot but couldn't find the way...
In your map view delegate, do this:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
[mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
Try using mapView.userTrackingMode = MKUserTrackingModeFollow;, you'll get smoother panning than using the location manager manually.
In addition note that there is a ready-made button for managing the various tracking states:
MKUserTrackingBarButtonItem.
The easiest way would be to create a new UIView on top of your map's view with a blue dot and only move the map's view.

How to recenter map in iPhone app on zoom in/out using MKMapView

I am developing an iPhone application in which I need to show an image at a specific Latitude & Longitude on a Map. The requirement is - Even if the user zooms in or out on this map screen, the map control should automatically center itself after the zoom, to the same Lat & Long. I am using MKMapView.
I have tried to go through all available documentation. However, I could not come across any callback or other method that will allow me to achieve the objective.
One alternative is to handle touch events. However, I find that as a very complicated solution. And I hope that a simpler alternative exists. Any ideas on the above?
Can you please help? Any example will be appreciated.
Implement MKMapViewDelegate and then try this:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[mapView setCenterCoordinate:locationManager.coordinate animated:NO];
}
Replace locationManager with whatever the name of your CLLocationManager is.