Xcode如何保存地图注释



我是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];

        }
    }];

这就是如何将一个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)];

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

还可以看看cachePolicy,您可以使用它来让解析SDK为您存储数据,这样您就不必担心核心数据或NSUserDefaults了。

最新更新