2

我想根据 gps 位置存储带有附加数据的坐标,并在带有图钉注释的地图中查看坐标以及标注(标题、副标题)中的附加数据。我已经设法通过蓝牙将我的数据从我的设备传输到我的 iPhone。我大约每秒都会获得新坐标,但我的设备非常慢,所以我只需要每 10 米保存一次坐标和附加数据。我是 iOS 编程新手,期待您的帮助!;) 这是我的代码:

视图控制器.m

@interface SecondViewController ()

@end

extern float lat;
extern float lon;

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self setupGradients];
    _mapView.showsUserLocation = YES;



}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if (lat > 0) {
            double pointOneLatitude = lat;
            double pointOneLongitude = lon;
            CLLocationCoordinate2D pointOneCoordinate = {pointOneLatitude,         pointOneLongitude};
            KTMapAnnotation *pointOneAnnotation = [[KTMapAnnotation alloc]     initWithCoordinate:pointOneCoordinate];
            [pointOneAnnotation setTypeOfAnnotation:PIN_ANNOTATION];
             [self.mapView addAnnotation:pointOneAnnotation];
    }


}

视图控制器.h

   import <UIKit/UIKit.h>
   import <MapKit/MapKit.h>
   import "KTMapAnnotation.h"
   @interface SecondViewController : UIViewController
   @property (weak, nonatomic) IBOutlet MKMapView *mapView;

KTMapAnnotation.h

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

    CLLocationCoordinate2D _coordinate;
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;


// 08 - Add a Callout
- (NSString*) title;
- (NSString*) subtitle;

@property(nonatomic, strong) NSString *typeOfAnnotation;

@end

KTMapAnnotation.m

#import "SecondViewController.h"

#import "KTMapAnnotation.h"

@implementation KTMapAnnotation

@synthesize coordinate=_coordinate;

@synthesize typeOfAnnotation;


- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate
{
    self = [super init];

    if (self != nil)
    {
        _coordinate = coordinate;
    }

    return self;
}

- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate
    {
        _coordinate = newCoordinate;
    }
    // Add a Callout
    - (NSString*) title
    {
        return @"Title“;
    }

    // Add a Callout

    - (NSString*) subtitle
    {
        return @„subtitel";
    }


@end
4

0 回答 0