MKPinAnnotationView not moving - iphone

I have went through a few links here, not all of them, regarding MKPinAnnotationView pin, subclass, etc. I did some simple tutorials online and when I thought I could start on my application with the knowledge from the tutorials, I was wrong. :(
In my tutorial file, I managed to do a simple MKPinAnnotationView *pin. Set its properties, like canShowCallOut = YES, draggable = YES. I can drag the pin anywhere I want to and display the location its dropped at.
But when I created my new application, I did the same thing again. But the pin isn't moving, is there something I did wrong?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
if([annotation isKindOfClass:[CustomPlacemark class]])
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES; // shows the black label when the pin is tapped
newAnnotation.draggable = YES;
// newAnnotation.enabled = YES;
newAnnotation.tag = tag;
NSLog(#"%# %#", [annotation title], [annotation subtitle]);
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
newAnnotation.rightCalloutAccessoryView = rightButton;
NSLog(#"Created annotation at: %f %f", ((CustomPlacemark*)annotation).coordinate.latitude, ((CustomPlacemark*)annotation).coordinate.longitude);
[newAnnotation addObserver:self
forKeyPath:#"selected"
options:NSKeyValueObservingOptionNew
context:#"GMAP_ANNOTATION_SELECTED"];
[newAnnotation autorelease];
tag++;
NSLog(#"ååååååååå %#", appDelegate.fml);
return newAnnotation;
}
return nil;
}

Take a look
http://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info
I'm looking for the same problem.

Related

Custom annotation error

I have an custom annotation set up in my mapview using below code. Problem is that the position of the annotation image is incorrect, it put's it a bit to the right of the actual location instead of spot on like when using the regular Pins.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:#"townhouse.png"]];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
Any help at all would be grateful!
/Marcus
Marcus,
use the centerOffset property of MKAnnotationView to move your custom annotation view.
annotationView.centerOffset = CGPointMake(xOffset, yOffest);

Can an Annotation Callout subtitle be a link that launches safari?

I want to add as a subtitle in a Callout Bubble of MKAnnotationPoint a link that launches Safari Browser that eventually goes to that link.Is this possible?
Why don't you use a button in the bubble, that's why it is designed for?
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
annotationButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[annotationButton addTarget:self action:#selector(annotationAction) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = annotationButton;
return annView;
}
- (void) annotationAction {
//Call a web view here
}

iPhone: MKMapAnnotationView: Current location has the same annotationView as other pins. How to make it unique?

Im using the following method to show MKAnnotation View on my mapView. But wehn I do that the current location of the user is also given the same view as the other pins. How can I make the current location a Unique pin color
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:#"currentloc"];
//annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:nil/*#selector(checkButtonTapped:event:)*/
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = myDetailButton;
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
In your viewForAnnotation method, check to see if the annotation is an instance of MKUserLocation. If it is, return nil:
if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;

MapView annotation

I have added an image on annotation view and when i am touching annotation view its image is changeing into red pin can any one tell me what's he reason for it
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView* newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"annotation1"];
if (annotation == _mapView.userLocation)
{
newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return nil;
}
//[newAnnotation setSelected:YES];
newAnnotation.image = [UIImage imageNamed:#"sample.png"];
newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
newAnnotation.canShowCallout = YES;
[newAnnotation retain];
return newAnnotation;
}
Make the newAnnotation a MKAnnotationView rather than a MKPinAnnotationView.

Customise googlemap viewport in iphone

m stucked in figuring out how can i set the viewport for my google map markers.
is there any way to do it in objC??
or i have to do it in my map itself??? if yes, then how???
My code for google map just shows the maps along with the markers,but when i click it,it just shows the name of the place in a small box.. :(
how to make it a proper viewport???
here's the viewport image:
1) You can subclass MKAnnotationView. I think it's the best way to solve your problem.
2) You can customize your annotation callout view, e.g:
- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString* ItemAnnotationIdentifier = #"itemAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[theMapView dequeueReusableAnnotationViewWithIdentifier:ItemAnnotationIdentifier];
if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:ItemAnnotationIdentifier]
autorelease];
customPinView.canShowCallout = YES;
UIImage *logo = [ImageProcessor scaleImage:[UIImage imageNamed:#"logo.png"] toSize:CGSizeMake(30, 30)];
customPinView.leftCalloutAccessoryView = [[[UIImageView alloc] initWithImage:logo] autorelease];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
rightButton.tag = [((ItemAnnotation *)annotation).itemId intValue];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}