地图视图上可拖动的图钉
您好,我正在尝试创建一个可拖动的图钉,但是当我尝试移动图钉时它没有移动,只有地图移动并且图钉停留在 smae 位置,我做错了。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKPinAnnotationView *test=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
if([annotation title]==@"Parked Location")
{
//
[test setUserInteractionEnabled:YES];
[test setCanShowCallout:YES];
[test setDraggable:YES];
return test;
}
[
return test;
}
我的自定义注释类也像这样,
- (NSString *)subtitle{
return @"Put some text here";
}
- (NSString *)title{
return @"Parked Location";
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate
{
coordinate=newCoordinate;
}
但它不起作用,为什么......?
Hi am trying to create a draggable pin , but it not moving when i try to move the pin only the map moves around and the pin stays at the smae position what m i doing wrong.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKPinAnnotationView *test=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
if([annotation title]==@"Parked Location")
{
//
[test setUserInteractionEnabled:YES];
[test setCanShowCallout:YES];
[test setDraggable:YES];
return test;
}
[
return test;
}
also my custom annonation class is like these
- (NSString *)subtitle{
return @"Put some text here";
}
- (NSString *)title{
return @"Parked Location";
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate
{
coordinate=newCoordinate;
}
but its not working why...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是旧的,但以防万一有人对未来感兴趣:
如果没有|标题|为 MKPinAnnotationView 设置,拖动也不起作用。
This is old but incase anyone is interested in the future:
If no |title| is set for the MKPinAnnotationView, dragging won't work either.