gpt4 book ai didi

ios - Mapkit 带有 pin 的新注释,没有弹出窗口

转载 作者:行者123 更新时间:2023-12-01 19:23:32 24 4
gpt4 key购买 nike

我刚刚创建了一个新应用程序,并且在 View 中实现了一个 map 。
我已经创建了带有一些个人注释的 map ,但是当用户触摸图钉时,不会出现任何内容。我试图设置图钉的颜色,但似乎没有任何效果。我需要用户在触摸 pin 时可以触摸弹出窗口上的公开按钮,以使用“本地 map ”。
现在,当我触摸别针时,这个会变暗,但没有别的。
有人能帮我吗?请!!

io ne avrei bisogno, per far aprire poi un 披露 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,.... hoguardato i tutorial ma non trovo l'errore!

头子类

 #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 myAnnotation

@synthesize titolo;
@synthesize sottotitolo;
@synthesize coordinate;

-init{
return self;

}

@end

文件 .m View Controller
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]);

然后这个片段来显示和个性化pin
-(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;
}

最佳答案

MKAnnotation协议(protocol)要求类响应 titlesubtitle .属性必须完全如此命名。

尽管您也可以拥有自己的不同名称的属性,但 map View 不会调用它们(它正在寻找 titlesubtitle )。

对于披露按钮,在 viewForAnnotation ,设置rightCalloutAccessoryViewUIButton并在 calloutAccessoryControlTapped 中响应它的点击委托(delegate)方法。

在该委托(delegate)方法中,您可以使用 (myAnnotation *)view.annotation 访问注释对象。然后调用openURL打开 map 应用程序。

关于ios - Mapkit 带有 pin 的新注释,没有弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com