8

In the iOS 8.0 default map application, when you tap the POI point, you get detailed information including the name of the POI and address.

My question is:

  1. Is it possible to do the same as this using MKMapView or IOS native code?

  2. If not, how can I get the POI data with the map scale (because the POI point shown on the map relies on the region and scale). So, I need to fetch the data to know which POI point shows based on this region and scale.

1 Answer 1

4
+50

For get detailed information including the address of the POI I think you can do this in two steps:

  1. Get the coordinate of your POI

  2. Convert them for get address info; see this beautiful example:

    CLGeocoder *ceo = [[CLGeocoder alloc]init];
    CLLocation *loc = [[CLLocation alloc]initWithLatitude:32.00 longitude:21.322]; //insert your coordinates
    
    [ceo reverseGeocodeLocation:loc
          completionHandler:^(NSArray *placemarks, NSError *error) {
             CLPlacemark *placemark = [placemarks objectAtIndex:0];
             NSLog(@"placemark %@",placemark);
             //String to hold address
             NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
             NSLog(@"addressDictionary %@", placemark.addressDictionary);
    
             NSLog(@"placemark %@",placemark.region);
             NSLog(@"placemark %@",placemark.country);  // Give Country Name
             NSLog(@"placemark %@",placemark.locality); // Extract the city name
             NSLog(@"location %@",placemark.name);
             NSLog(@"location %@",placemark.ocean);
             NSLog(@"location %@",placemark.postalCode);
             NSLog(@"location %@",placemark.subLocality);
    
             NSLog(@"location %@",placemark.location);
             //Print the location to console
             NSLog(@"I am currently at %@",locatedAt);
         }
         else {
             NSLog(@"Could not locate");
         }
    ];
    

If you need to center on a region your map you can do it just like this:

- (void)gotoLocation
{
    MKCoordinateRegion newRegion;

    newRegion.center.latitude = NY_LATITUDE;
    newRegion.center.longitude = NY_LONGTITUDE;

    newRegion.span.latitudeDelta = 0.5f;
    newRegion.span.longitudeDelta = 0.5f;

    [self.myMapView setRegion:newRegion animated:YES];
}

I hope these code examples can help you :)

For learn more about MKMapViewClass (I recommend it) check the Apple Documentation or this beatiful example on how to manage POI with Apple Maps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.