Hello! i've just created a new app, and i've implemented a map in a view.
I've created the map with some personal annotation but, when the user touch the pin, doesn't appear anything. I've tried to set the colour of the pin but nothing seem's to work. I need that the user, when touch the pin, can touch the disclosure button on the popup, to use "native maps".
Now, when i touch the pin, this one become darker, but nothing else.
Can someone help me? Please!!
io ne avrei bisogno, per far aprire poi un disclosure e far aprire l'app nativa mappe per creare il percorso!! Se ora tocco il pin, questo diventa pił scuro ma non succede nulla! non riesco nemmeno ad agire su di loro per cambiare colore, immagini,.... ho guardato i tutorial ma non trovo l'errore!
header subclass
Code:
#import <Foundation/Foundation.h>
#import <MapKit/Mapkit.h>
@interface myAnnotation : NSObject <MKAnnotation>{
CLLocationCoordinate2D coordinate;
NSString *titolo;
NSString *sottotitolo;
}
@property(nonatomic,assign) CLLocationCoordinate2D coordinate;
@property(nonatomic,copy) NSString *titolo;
@property(nonatomic,copy) NSString *sottotitolo;
@end
implementation subclass
Code:
@implementation myAnnotation
@synthesize titolo;
@synthesize sottotitolo;
@synthesize coordinate;
-init{
return self;
}
@end
file .m view controller
Code:
CLLocation *userLoc = myMapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
myMapView.delegate=self;
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 45.;
theCoordinate1.longitude = 7.;
CLLocationCoordinate2D theCoordinate2;
theCoordinate2.latitude = 45.;
theCoordinate2.longitude = 12.;
CLLocationCoordinate2D theCoordinate3;
theCoordinate3.latitude = 45.;
theCoordinate3.longitude = 8.;
CLLocationCoordinate2D theCoordinate4;
theCoordinate4.latitude = 43.;
theCoordinate4.longitude = 7.;
myAnnotation* myAnnotation1=[[myAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
myAnnotation1.titolo=@"xxxx";
myAnnotation1.sottotitolo=@"xxx";
myAnnotation* myAnnotation2=[[myAnnotation alloc] init];
myAnnotation2.coordinate=theCoordinate2;
myAnnotation2.titolo=@"yyyy";
myAnnotation2.sottotitolo=@"yyyy";
myAnnotation* myAnnotation3=[[myAnnotation alloc] init];
myAnnotation3.coordinate=theCoordinate3;
myAnnotation3.titolo=@"zzz";
myAnnotation3.sottotitolo=@"zzz";
myAnnotation* myAnnotation4=[[myAnnotation alloc] init];
myAnnotation4.coordinate=theCoordinate4;
myAnnotation4.titolo=@"kkk";
myAnnotation4.sottotitolo=@"kkk";
[myMapView addAnnotation:myAnnotation1];
[myMapView addAnnotation:myAnnotation2];
[myMapView addAnnotation:myAnnotation3];
[myMapView addAnnotation:myAnnotation4];
[annotations addObject:myAnnotation1];
[annotations addObject:myAnnotation2];
[annotations addObject:myAnnotation3];
[annotations addObject:myAnnotation4];
NSLog(@"%d",[annotations count]);
and then this snippet to show and personalize the pin
Code:
-(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 = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Thank You!