2

GPS の位置に応じて座標を追加データとともに保存し、ピン注釈とコールアウト (タイトル、サブタイトル) の追加データを使用してマップで座標を表示したいと考えています。Bluetooth経由でデバイスからiPhoneにデータを取得することができました。私は毎秒新しい座標を取得しますが、私のデバイスは非常に遅いので、必要なのは座標と追加データを 10 メートルごとに保存することだけです。私はiOSプログラミングの初心者で、あなたの助けを楽しみにしています! ;) ここに私のコードがあります:

ViewController.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];
    }


}

ViewController.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