0

I'm using the Google Places API to show places near the user's location. When they tap on a pin, the annotation view pops up with the name and the vicinity. There's also a detail disclosure button that segues into a detail view controller which is supposed to show all the details of that specific place.

Here is how I get the data of ALL the names, place id's, and image strings for ALL the places near the user:

 NSArray* places = [json objectForKey:@"results"];
NSArray *icons = [places valueForKey:@"icon"];
NSArray *placeIDs = [places valueForKey:@"place_id"];
NSArray *names = [places valueForKey:@"name"];
for (NSString *imgString in  icons)
{
    NSLog(@"%@", imgString);
}

for (NSString *placeID in placeIDs)
{
    NSLog(@"%@", placeID);
}

for (NSString *theName in names)
{
    NSLog(@"%@", theName);
}

if ([places count] == 0)
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Couldn't find any of those places near you" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil];
    [alertView show];
}


[self plotPositions:places];

So as you can see I'm just looping through the arrays and retrieving ALL the data. Now all I want to do is retrieve the data of the place that the user has TAPPED on.

All help is appreciated, thanks in advance

doc92606
  • 691
  • 2
  • 11
  • 32
  • Have you implemented the calloutAccessoryControlTapped delegate method? Do you annotation objects know what their placeId is? –  Aug 02 '14 at 01:40
  • I have that delegate method and I use it to segue into the details view. I can also loops through all the placeId's but I don't know if my annotation objects know what their placeId is... – doc92606 Aug 02 '14 at 01:42
  • Add a placeId property to your annotation class (the one that implements the MKAnnotation protocol) and set it when creating the annotation. Then you can easily get it in the callout...Tapped method. If you're using the built-in MKPointAnnotation class, you'll need to define a custom one instead. See http://stackoverflow.com/questions/20449716/custom-annotation-apple-mapkit, http://stackoverflow.com/questions/5939223/store-data-in-mkannotation, http://stackoverflow.com/questions/22572342/how-to-access-to-an-annotation-attribute-inside-method-calloutaccessorycontrolta. –  Aug 02 '14 at 01:49
  • oh I'm not using a custom class, i just created an instance of annotation – doc92606 Aug 02 '14 at 01:51
  • If you mean you're using MKPointAnnotation, you'll need to switch to a custom class to make this easier. See the links for examples of custom annotation classes. –  Aug 02 '14 at 01:56

0 Answers0