Disable MKPlacemark showing/hiding title in iPhone - iphone

I have MKMapView with MKPlacemark on it. When showing the map, I'm showing place mark's title.
Everything is fine until now.
I want to disable hiding title when user touches it.
I tried to add
myMapView.userInteractionEnabled = NO;
myMapView.multipleTouchEnabled = NO;
Which helps, but completely disables interaction with map. I want to leave a possibility to zoom in/out and moving the map.

Instead of creating PIN, create your custom annotation. In custom annotation create the view with all the info that you want to present to user, and disable the place mark. By that you are not suppose to handle taps but you will show all the static/dynamic info attached to one lattitude/longitude.

The following code did the trick
for (UIGestureRecognizer *g in [myMapView gestureRecognizers])
[myMapView removeGestureRecognizer:g];

In MapKit Delegate method try bellow code
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *defaultPinID = #"com.invasivecode.pin";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[yourMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
if (annotation == yourMapview.userLocation)
return nil;
pinView.pinColor = MKPinAnnotationColorRed;
pinView.userInteractionEnabled = NO;
//pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
return pinView;
}
here if you use your placemark with this logic may its work....
hope,this help you...
:)

Related

How to select a map pin programmatically

I am new to Maps Concept.
Please find the attached image once.
when i click the "pin" i am getting message says "Admire your smile" or any text..... Now i want like... when we select the table view, i need to raise that message for that pin(with out user interaction for that pin)...
I am using below code for This maps and pins.
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
customLocation.latitude=[casesobjc.latitude_string doubleValue];
customLocation.longitude=[casesobjc.longitude_string doubleValue];
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:casesobjc.locationForMap_string andCoordinate:customLocation];
[mapView addAnnotation:newAnnotation];
}
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: #"annotation_ID"];
if (pin == nil) {
pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: #"annotation_ID"];
} else {
pin.annotation = annotation;
}
pin.pinColor = MKPinAnnotationColorPurple;
pin.animatesDrop = YES;
pin.canShowCallout=YES;
return pin;
}
Now i will show all the pins once like below.
How to do When we click on table view i need to show the title for that pin like how we show when we select a pin?
Thanks in Advance
The method that you are looking for is selectAnnotation:.
In your didSelectRowAtIndexPath, you have to find the annotation associated with the table row.
Once you find it, you can tell it, to select it by using:
[mapView selectAnnotation:foundAnnotation animated:YES];
The same as the Objective C answer, in your tableview you have a list of annotations. In Swift in the didSelectRow:
For Swift 4:
// annotations would be the array of annotations - change to your required data sets name
let selectedAnnotation = annotations[indexPath.row]
self.mapView.selectAnnotation(selectedAnnotation, animated: true)
Short and simple.

How to create a callout bubble MKAnnotationView that respond to touches

I'm trying to make a custom annotation view able to respond to touches without success.
Thanks to this question I was able to made an annotation view close to what I want customize callout bubble for annotationview? also seen this How to capture touches and NOT dismiss the callout? but the problem is quite different
The first thing I've done so far is subclassing an MKAnnotationView and override the -setSelected:animated: method
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if(selected)
{
MyCallOut * callOut=[MyCallOut createMyCallOut];
callOut.tag=555;
[self.superview addSubview:callOut];
}
else
{
// [[self viewWithTag:555] removeFromSuperview];
//Remove my custom CallOut
}
}
The problem is that the map view is eating all the touches event, my custom callout has two buttons but no action is triggered pressing them.
In one of my experiment I've tried to add the callout view to the MKAnnotationView superview (the mapView) everything seems to be fine while I scroll, but If I zoom the callout moves around.
you have to add call out accessory view in map annotation
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pinView;
}
else {
[mapView.userLocation setTitle:#"I am here"];
}
return pinView;
}
and for click event of your call out
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
}
Solved looking to this link Custom annotation and callouts, the other tricky part is implement a correct way to press button on the fake callout. I managed this part creating a boolean value that understands the number of annotation/parentAnnotation on screen and choose when one could disappear or not.Just need to make the CalloutAnnotation available to selection.

Change Pin Color when user tapped

I would change the color from red to green of an annotation when the user pin tapped addition to changing its title and subtitle.
I am truly lost. I searched how to make a custom annotation pin, ok. I found the implementation of the method when the user touches the pin didSelectAnnotationView and it works when I tap the annotation NSLog(#"Tap") ; , but now I can not change the pin that was touched.
Thank you very much everyone for your contributions.
Ciao
To set the pin color, make use of MKPinAnnotationView pinColor property.
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] init]
pin.pinColor = MKPinAnnotationColorGreen;
For custom annotation image, set the image property, as such.
UIImage *annImage = [UIImage imageNamed:#"AnnotationIcon.png"];
annView.image = annImage;
Do note that the MKPinAnnotationView animateDrop property will not work on custom images. There's a way to duplicate that animation though. See How do I animate MKAnnotationView drop?
Update
So bascially, you do this if you wanna change from red to green upon being selected.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view {
view.pinColor = MKPinAnnotationColorGreen;
}
- (MKAnnotationView *)mapView:(MKMapView *)aMapView
viewForAnnotation:(id)ann {
NSString *identifier = #"myPin";
MKPinAnnotationView *annView = (MKPinAnnotationView *)
[aMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annView == nil) {
annView= [[[MKPinAnnotationView alloc] initWithAnnotation:ann
reuseIdentifier:identifier]
autorelease];
} else {
annView.annotation = ann;
}
// you can define the properties here.
return annView;
}
In your method set the pinColor property of your MKAnnotationView as follows:
annotationView.pinColor = MKPinAnnotationColorRed; // Green or Purple
(re) look this :
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view {
view.pinColor = MKPinAnnotationColorGreen;
}
this is a MKPinAnnotationView (and not MKAnnotationView) in param

How to display Annotation view without clicking on pin in mapview?

I have implemented one map application in which i have display pin animation for current location.When i click on the pin at that time annotation view will open. But i want to display
annotation view without clicking on pin.Is it possible if possible then please give me idea about that.
Thanks in advance.
Try out:
It seems that [mapView selectAnnotation:annotation animated:YES] works too.
Hope this helps.
You just need to find your MKAnnotationView instance you want to select and call -setSelected:animated:.
For example, you can loop your annotations of an MKMapView like this:
for (YOURCLASSHERE *a in mapView.annotations) {
// Your current position (if shown) is an annotation as well. Thus check for the right class!
if ([a isKindOfClass:[YOURCLASSHERE class]]) {
// insert some smart if statement here, if you have multiple annotations!
[[mapView viewForAnnotation:a] setSelected:YES animated:YES];
}
}
YOURCLASSHERE is your class which implements the MKAnnotation protocol.
Of course the loop is superfluous if you already know your annotationView.
We can show the annotation with out clicking on it. Use the following code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *identifier = #"Pin";
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pin.canShowCallout = YES;
[pin setSelected:YES animated:NO];
return [pin autorelease];
}

Monotouch MapKit - annotations - adding a button to bubble

Anyone know if there's anyway to get a button onto an annotation?
I'd like the location to be selectable - so you can say.. select the location and get all the events at that location by clicking on the button.
is this possible?
w://
Here's the code I used for my annotation, it includes a button on the right side of the bubble. You can set an IBAction to push a new view onto the stack to display whatever you want
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"myPin";
pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
//instatiate a detail-disclosure button and set it to appear on right side of annotation
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
I just helped someone else with this in objective c, but I'm sure the concept is the same with mono. You need to create a custom MKAnnotationView object and override the GetViewForAnnotation (viewForAnnotation in obj-c) method of your MKMapViewDelegate class... check out the other question.
When you create your custom MKAnnotationView object it is basically a UIView made for map annotations... you can just add your button and other info to the view and it will show up when the user hits the annotation.
Here some rough code for the delegate method:
public override MKAnnotationView GetViewForAnnotation(
MKMapView mapView,NSObject annotation) {
var annotationId = "location";
var annotationView = mapView.DequeueReusableAnnotation(annotationId);
if (annotationView == null) {
// create new annotation
annotationView = new CustomAnnotationView(annotation, annotationId);
}
else {
annotationView.annotation = annotation;
}
annotation.CanShowCallout = true;
// setup other info for view
// ..........
return annotationView;
}
}