标签: mkannotation

将数据存储在MKAnnotation中?

所以我对Xcode和Objective-C很陌生.我有几个ArtPiece对象,各种属性存储在一个数组中.然后我将它们作为MKAnnotations添加到mapview.我需要做的是在点击时发送它们来自的阵列位置的引用.我相信MKAnnotations只有数据成员标题,图像和位置,因此当我从对象创建MKAnnotation时,注释不会保留任何其他属性.所以,我的问题是,我如何设法保持对创建注释的对象的数组位置的引用,以便我可以将其发送到其他方法,以便他们可以从数组中检索有关该对象的其他信息以获取详细信息views等有没有办法在注释中存储单个int值?我不认为还有其他想法吗?

这是我的ArtPiece.h:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface ArtPiece : NSObject <MKAnnotation>{

    NSString *title;
    NSString *artist;
    NSString *series;
    NSString *description;
    NSString *location;
    NSString *area;
    NSNumber *latitude;
    NSNumber *longitude;
    UIImage *image;
}

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *artist;
@property (nonatomic, retain) NSString *series;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *location;
@property (nonatomic, retain) NSString *area;
@property (nonatomic, retain) NSNumber *latitude;
@property (nonatomic, retain) NSNumber *longitude;
@property (nonatomic, retain) UIImage *image;


@end
Run Code Online (Sandbox Code Playgroud)

这是.m:

#import "ArtPiece.h"
#import …
Run Code Online (Sandbox Code Playgroud)

arrays xcode objective-c mkmapview mkannotation

15
推荐指数
1
解决办法
5937
查看次数

为当前位置注释设置canShowCallOut = NO,iPhone

我正在使用当前位置图标的自定义调出(标题和副标题).我尝试了以下来禁用默认注释,但它不起作用.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    NSLog(@"viewForAnnotation");
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        MKAnnotationView *userLocationView = [mapView viewForAnnotation:annotation];
        userLocationView.canShowCallout = NO;
        NSLog(@"[annotation isKindOfClass:[MKUserLocation class]");
        return nil;
    }

}
Run Code Online (Sandbox Code Playgroud)

只有它的工作方式是

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)ann
{
    if([ann.annotation isKindOfClass:[MKUserLocation class]] )
    {
       [mymap deselectAnnotation:ann.annotation animated:NO];
    }
}
Run Code Online (Sandbox Code Playgroud)

但它有时会滞后.是否有其他方法可以禁用当前位置注释的默认标注视图?任何帮助将不胜感激.

objective-c mkannotation ios currentlocation

15
推荐指数
2
解决办法
1万
查看次数

iOS:Swift - 如何在触摸时添加精确定位点并获取该位置的详细地址?

我想在触摸iOS地图时添加注释并获取相应位置的详细地址(地标).我如何在Swift中实现这一目标?

提前致谢.

dictionary mkannotation ios mkpointannotation swift

15
推荐指数
2
解决办法
2万
查看次数

像Uber iOS应用程序一样在地图上移动注释

我正在开发一个项目,我需要为UBER和OLA创建类似的iOS应用程序,其中汽车根据位置移动.我正在寻找某种类型的图书馆,它可以让汽车像OLA一样顺畅地转动.现在我能够将汽车从一个纬度经度移动到另一个纬度经度.但复杂的部分是如何转向并确保汽车在朝向方向时面向前方.

请查看以下屏幕截图.

截图

objective-c latitude-longitude mkmapview mkannotation xcode8

15
推荐指数
1
解决办法
6401
查看次数

如何隐藏MKAnnotationView标注?

我试图隐藏AnnotationView而不接触引脚,可能吗?谢谢!

for (id currentAnnotation in self.mapView.annotations) {        
if ([currentAnnotation isKindOfClass:[MyAnnotation class]]) { 
    } 
}
Run Code Online (Sandbox Code Playgroud)

iphone sdk callouts mkannotation mkannotationview

14
推荐指数
1
解决办法
6022
查看次数

如何自动对MKAnnotations进行缩放级别分组?

如果用户缩小MKMapView,我希望彼此接近的MKAnnotations自动分组为一个"组"注释.如果用户缩放,则应将"组"注释再次拆分为唯一/原始注释.

苹果已经在iOS 4 Photos.app中做到了这一点

是否有一种常见的"预定义"方式来做到这一点?

iphone zoom mapkit mkmapview mkannotation

14
推荐指数
2
解决办法
2722
查看次数

如何为MKAnnotation的字幕显示2行文本并更改右侧按钮的图像?

我正在查看Apple的MapCallouts示例,用于地图注释和标注(==当您点击图钉时出现的气泡).每个注释都有坐标,标题和副标题.我想在2行显示字幕,我试过:

- (NSString *)subtitle
{
return @"Founded: June 29, 1776\nSecond line text";
}
Run Code Online (Sandbox Code Playgroud)

但文本"第二行文字"保持在一行,使泡沫更宽.我明白了:

在此输入图像描述

我还想将按钮的图像更改为我自己的图像,设置按钮的代码当前是这样的:

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

编辑:我尝试了7KV7的建议.按钮更改成功,但我仍然无法获得2行字幕.我的代码:

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                        initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
        customPinView.pinColor = MKPinAnnotationColorPurple;
        customPinView.animatesDrop = YES;


        // Button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, 23, 23);
        button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

        //UIEdgeInsets titleInsets = UIEdgeInsetsMake(7.0, -20.0, 7.0, 7.0);
        //button.titleEdgeInsets = titleInsets;

        [button setImage:[UIImage imageNamed:@"ic_phone_default.png"] forState:UIControlStateNormal];
        //[button setImage:[UIImage imageNamed:@"ic_phone_selected.png"] forState:UIControlStateSelected];
        [button setImage:[UIImage imageNamed:@"ic_phone_selected.png"] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(showDetails:) …
Run Code Online (Sandbox Code Playgroud)

iphone mkmapview mkannotation

14
推荐指数
2
解决办法
3万
查看次数

在MKMapView中显示多个注释标注

是否可以同时打开多个标注?

代码:

- (void)mapViewDidFinishLoadingMap:(MKMapView *)theMapView {
    for (id<MKAnnotation> currentAnnotation in theMapView.annotations) {
        [theMapView selectAnnotation:currentAnnotation animated:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

只打开一个标注.

iphone mkmapview mkannotation

13
推荐指数
2
解决办法
9714
查看次数

自定义MKAnnotation标注气泡

我的应用程序地图页面中有一个要求.我必须自定义Callout气泡.我需要添加一个图像,两个标签和一个具有特定高度和宽度的按钮.

我已经浏览了网页,找不到解释如何自定义标注气泡的正确链接.如果你们中的任何一个遇到或了解它,请与我分享.

任何简单的例子或链接都会非常棒.

在此先感谢suresh

iphone objective-c mkmapview mkannotation ios

13
推荐指数
1
解决办法
2万
查看次数

在地图视图上拖动注释引脚

注释引脚是可拖动的,但我无法将其放到目标位置.问题是如何获取目标位置的坐标,我放下注释引脚?有任何方法吗?

编辑1:

注释引脚的中心似乎永远不会改变我放下引脚的地方.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState 
fromOldState:(MKAnnotationViewDragState)oldState 
{
if (newState == MKAnnotationViewDragStateEnding)
{
    NSLog(@"x is %f", annotationView.center.x);
    NSLog(@"y is %f", annotationView.center.y);

    CGPoint dropPoint = CGPointMake(annotationView.center.x, annotationView.center.y);
    CLLocationCoordinate2D newCoordinate = [self.mapView convertPoint:dropPoint toCoordinateFromView:annotationView.superview];
    [annotationView.annotation setCoordinate:newCoordinate];

}
}
Run Code Online (Sandbox Code Playgroud)

编辑2:

Annotation.h

@property (nonatomic,readwrite,assign) CLLocationCoordinate2D coordinate;
Run Code Online (Sandbox Code Playgroud)

Annotation.m

- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate {
coordinate = newCoordinate; 
}
Run Code Online (Sandbox Code Playgroud)

编辑3: 我在哪里拖动引脚,掉落的NSLog输出总是相同的.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState 
fromOldState:(MKAnnotationViewDragState)oldState 
{
if (newState == MKAnnotationViewDragStateEnding)
{
    CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
    NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
}
} …
Run Code Online (Sandbox Code Playgroud)

iphone draggable mkannotation ios

13
推荐指数
1
解决办法
2万
查看次数