xcode iOS,显示从解析中检索到的用户位置 Objective-C

xcode iOS, Displaying user locations retrieved from parse Objective-C

目前我的应用程序允许用户首先保存一个位置,称为 eventParse。然后用户可以按一个按钮从 Parse 中检索所有存储的位置,这些位置使用以下代码放入数组中:

-(void) retrieveEventsFromParse {
    PFQuery *query = [PFQuery queryWithClassName:@"events"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        eventsArray =[[NSMutableArray alloc] initWithArray: objects];
        if (!error) {
            NSLog(@"Successfully retrieved %lu locations.", (unsigned long)objects.count);
            // Do something with the found objects
            for (PFObject *object in objects) {

                NSString *location = [object objectForKey:@"location"];
                NSLog(@"object with id %@ has location %@", object.objectId, location);

            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
}

但是,我在将这些检索到的位置显示为地图上的图钉时遇到了问题。我想知道如何将数组对象之一(下面的示例)变成地图上的图钉。

\"<-27.47143300,+153.02720500> +/- 0.00m (speed -1.00 mps / course -1.00) @ 6/26/15, 9:47:11 AM Australian Eastern Standard Time\";\n}"

我想过使用 Regex 来切出 long,lat,但老实说我不知道​​如何处理这个问题。非常感谢任何帮助。

您可以看看如何使用 PFGeoPoint 而不是将它们存储为 NSString。然后,您可以通过调用 PFGeoPoint 的有效实例的 属性 来访问纬度和经度。以下内容来自 PFGeoPoint 文档:

/*!
 @abstract Latitude of point in degrees. Valid range is from `-90.0` to `90.0`.
 */
@property (nonatomic, assign) double latitude;

/*!
 @abstract Longitude of point in degrees. Valid range is from `-180.0` to `180.0`.
 */
@property (nonatomic, assign) double longitude;

至于怎么把图钉放到地图上,这两个帖子应该会有帮助:

Drop pin in center of the screen, MKMapView

How to add a push pin to a MKMapView(IOS) when touching?