0

At the moment my application allows users to first save a location, called an event to Parse. Then the user can press a button to retrieve all of the stored locations from Parse, which are put into an array using the following code:

-(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]);
        }
    }];
}

I am having trouble, however, displaying these retrieved locations as pins on a map. I was wondering how would I turn one of the array objects (example below) into a pin on the map.

\"<-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}"

I thought of using Regex to cut out long,lat but I honestly have no idea as to how to approach this. Any help is much appreciated.

ErsatzRyan
  • 3,033
  • 1
  • 26
  • 30
rob25659
  • 5
  • 1
  • the output you have shown is not an array. Is that a string? Where did it come from in your code? Show what your "location" key looks like – Sam B Jun 26 '15 at 01:46
  • I thought the output was a string, but it turned out to be a PFObject. So I converted it to a string and cut the lat-long coords out to use with Lucas' suggestion. What I posted, by the way, was one element of array (which contained about 30 of those). – rob25659 Jul 23 '15 at 06:13

1 Answers1

0

You can take a look at how to use PFGeoPoint instead of storing them as NSString. Then, you can access the latitude and longitude by calling the property of a valid instance of PFGeoPoint. The following is from PFGeoPoint docs:

/*!
 @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;

As for how to put pin onto the map, these two posts should be helpful:

Drop pin in center of the screen, MKMapView

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

Community
  • 1
  • 1
Lucas Huang
  • 3,998
  • 3
  • 20
  • 29