Xcode如何保存地图注释?

时间:2015-03-26 17:28:14

标签: ios objective-c parse-platform

我是mapkit的新手,我想出了如何创建地图引脚,但在网络空间中绝对没有关于如何在Xcode中保存地图注释引脚的教程。你们中的任何人都知道如何做到这一点。我是核心数据吗?它是NSuserdefaults吗?

我使用Parse来存储地图引脚的经度和纬度,但我一次只能检索一个坐标。 你有没有任何建议我可以拉下多个注释引脚。如何保存多个注释引脚并将其加载到地图上?请帮我。

PFQuery *que = [PFQuery queryWithClassName:@"map"];
    [que orderByDescending:@"createdAt"];
    que.limit=10;


    [que getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
        if (!error) {
            NSLog(@"%@", [object objectForKey:@"lati"]);
            goat.text=[object objectForKey:@"lati"];
            goat2.text=[object objectForKey:@"longi"];


            NSString *ps;
            NSString *ls;
            ps=goat.text;
            ls=goat2.text;
            // int value = [ps intValue];
            //int valu = [ls intValue];
            NSLog(@"GOO %@", ps);
            NSLog(@"GOO %@", ls);
            lat=[ps floatValue];
            lon =[ls floatValue];






            NSMutableArray *locationss=[[NSMutableArray alloc]init];
            CLLocationCoordinate2D dizhi;

            VP *myann;
            myann=[[VP alloc]init];


            dizhi.latitude =lat;
            dizhi.longitude =lon;


            myann.coordinate=dizhi;
            myann.title =@"arsenal";
            [locationss addObject:myann];

            NSLog(@"QAD %f", dizhi.latitude);
            NSLog(@"QAD %f", dizhi.longitude);

            MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = myann.coordinate;
            point.title = @"Where am I?";
            point.subtitle = addre.text;

            [mapview addAnnotation:point];


                               myann=[[VP alloc]init];
                                dizhi.latitude =lattude;
                                dizhi.longitude =longtude;

                               myann.coordinate=dizhi;
                               myann.title =@"gees";
                                [locationss addObject:myann];

                               [mapview addAnnotations:locationss];


        }
    }];

2 个答案:

答案 0 :(得分:0)

这是您可以将一个CLLocationCoordinate2D保存并加载到NSUserDefaults的方法。

// Save
CLLocationCoordinate2D myCoord = ...
NSData *coordinateData = [NSData dataWithBytes:&myCoord length:sizeof(myCoord)];
[[NSUserDefaults standardUserDefaults] setObject:coordinateData forKey:@"MyCoordinate"];
[[NSUserDefaults standardUserDefaults] synchronize];

// Load
CLLocationCoordinate2D myCoord;
NSData *coordinateData = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyCoordinate"];
[coordinateData getBytes:&myCoord length:sizeof(myCoord)];

答案 1 :(得分:0)

调用findObjectsInBackgroundWithBlock:,它将返回(最多)10个位置对象的数组,供您迭代。

另请参阅cachePolicy,您可以使用它来解析SDK为您存储数据,然后您无需担心核心数据或NSUserDefaults