How to disable Accessibility for MKAnnotationView and Street in MKMapView - ios

I want to disable some pins on a map view. Setting isAccessibilityElement = NO is not working on MKAnnotationView somehow.
In addition, I found VoiceOver would iterate from street to street in the map view which may not make sense in some scenarios.
So is there other way to disable the Accessibility on MKAnnotationView and the street in the map?
Current code
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;
...//some setup
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView && ![annotationIdentifier isEqualToString:#""]) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
}
.../some config
// somehow no effect :(
annotationView.isAccessibilityElement = NO;
return annotationView;
}

Related

Custom Callout on MKAnnotationView

I wish to show a completely custom callout view on top of the MKAnnotationView when tapped. I have stumbled through a few answers but none of them have worked and I have seen it in a few apps so I know it can be done. I would also like to show a few buttons on the callout and perform different actions upon tapping on them. I am working on Objective-C and would really appreciate any help.
You need to put your custom code on viewForAnnotation method and update view as per your requirement:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
else if ([annotation isKindOfClass:[YOUR_CUSOM_ANNO_CLASS_NAME class]]) // use whatever annotation class you used when creating the annotation
{
static NSString * const identifier = #"customAnno";
MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView)
{
annotationView.annotation = annotation;
}
else
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier];
}
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:];
return annotationView;
}
return nil;
}
There is a wonderful demo by sghiassy on github. It will help you more to understand Annotation.
Starting with iOS 9 you can use the detailCalloutAccessoryView property on MKAnnotationView. You can set this to any view. You have a Ray Wenderlich tutorial for this on Chapter 14 of iOS 9 by Tutorials.

MKMapView - user current location blue dot covers the annotations

I am working on maps and when you tap a annotation it shows the title and description.
Problem is one annotation is very close to the user's current location so i can't see the title of that annotation because its not tapeable. When i try to tap the annotation nothing happens.
- (MKAnnotationView *) mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>) annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) {
//Don't trample the user location annotation (pulsing blue dot).
return nil;
}
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"pin"];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
if (pinView == nil)
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pin"];
if([[pinView.annotation title] isEqualToString:#"Store"])
{
pinView.pinColor = MKPinAnnotationColorGreen;
}
return pinView;
}
Is there anyway i can bring the annotation front that blue dot that shows current location?
So i moved
pinView.canShowCallout = YES;
in the last before returning the pinView and it worked.

How can i make custom pin and use FollowWithHeading mode together?

The following code below is show custom pin (picture as pin). it can use normally.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"Attraction"];
annotationView.canShowCallout = YES;
return annotationView;
}
Then use following code to show current location
[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];
XCODE jump to main.m and show
Thread 1:Signal SIGABRT
On the other hand if i use the following code
[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];
and unused all of the following code
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"Attraction"];
annotationView.canShowCallout = YES;
return annotationView;
}
Application will show current location normally but it's not show custom pin. It's show the red pin that is the default of system cause i've unused that code.
How can i make custom pin and use FollowWithHeading mode together?
..I'm sorry I do not use English well.
You need a slight change to your viewForAnnotation that examines the class of the annotation and returns the appropriate view. By returning nil the system will use the default view. You also need some additional code to implement view re-use correctly -
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView=nil;
if ([annotation isKindOfClass:[PVAttractionAnnotation class]]) // Note - put your custom annotation class here
{
annotationView =(MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"Attraction"];
if (annotationView == nil)
{
annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"Attraction"];
annotationView.canShowCallout = YES;
}
else
{
annotationView.annotation=annotation;
}
}
return annotationView;
}

Custom icon for location.Possible?

After much googling I'm nothing has come to my specific problem.
Is it possible to change the icon of the blue location dot with the circle?
I would like to replace the locator icon with my own icon.
Then save it to a different view with my own image.By pressing a button.Like a Annotation.
The result would be the location in the "AddPlace"View should store the location in a different View.
I use the MapKit Framework.
Yes, there is delegate method of MKMapView - viewForAnnotation, which is called also for the location pin. When annotation is kind of class MKUserLocation
Example:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) {
MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"pinViewLocation"];
if (!pinView) {
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pinViewLocation"];
pinView.canShowCallout = NO;
pinView.image = [UIImage imageNamed:#"map-location-pin"];
}
}
.....

setting the MKMapViewDelegate makes my marker disappear in iOS

I am using MapKit and I am having the exact problem.
This is my code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = #"MyLocation";
if ([annotation isKindOfClass:[MyLocation class]]) {
MKAnnotationView *annotationView = (MKAnnotationView *) [mymap_ios dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
} else {
annotationView.annotation = annotation;
}
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotationView;
}
return nil;
}
In this code, I can see the pin but not the blue button next to it so as. It seems that I have forgotten to do this:
mymap_ios.delegate=self;
But when I add this, the marker is not shown at all.
Can you help me on that?
When you don't set the map view's delegate, it doesn't call your viewForAnnotation and creates a default red pin without any accessory buttons.
When you set the delegate, it is calling your viewForAnnotation method but you are creating a plain MKAnnotationView which by default does not have any pre-set image or view (it's blank).
Either set the annotation view's image, add some content to the view, or simply create an MKPinAnnotationView instead of an MKAnnotationView:
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mymap_ios ...
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] init...
Also make sure that the annotation objects you add are of type MyLocation otherwise they will appear as plain red pins without an accessory button.

Resources