detail information about poi point in MKMapview
Asked Answered
Y

1

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.

Yalta answered 29/9, 2014 at 4:36 Comment(0)
P
4

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.

Phagocyte answered 8/6, 2015 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.