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.
Related
In my code, I'm calling
- (IBAction)goToUserLocation:(id)sender {
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
which then has this callback
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// I then try to set the region in here, which doesnt always work. Sometimes it zooms into the user location, then zooms back out to the region I specify. Other times, it will just stay zoomed in.
}
The MKUserTrackingModeFollow zooms in far more than I would like. I'd like to be able to set it so that it zooms into a region I specify. Is there a proper way to do this or is the region of MKUserTrackingModeFollow set?
Thank you!
viewForAnnotation is completely the wrong place. That is called when ever the map decides it needs to draw an annotation on the map. The map may not need to redraw an annotation if it was already on screen when someone pressed the button to goToUserLocation.
Instead try setting the zoomed out region before the tracking mode is set or after the animation is done.
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
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.
I have an maps application in which I show the points of interest in the map using pins. I want to represent the current location with the blue circle which is shown in Google maps. Is there any way we can add it. Can any one please help me with this. I really appreciate your time.
Thanks
You can get this by specifying nil in the appropriate delegate method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation {
if (annotation == mapView.userLocation) {
return nil;
}
}
This should cause MKMapView to use the default, which should be the blue circle.
You should set the setShowsUserLocation: property of your map view to YES. This can be done programmatically or in Interface Builder. Be careful, as I believe the simulator still shows the user location in Cupertino, CA.
Also, if you continue tracking the user and their movements, the blue indicator will continue to move as they do.
How to add overlay on a map in objective c?
(has any body tried it in iphone os 4.0)?
here is a good article on using the MKPolyline overlay to add a route type annotation to your map. It should give you an idea how to add any of the other overlays. just implement the
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
on your map delegate and give it the type of overlay your are drawing.