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:
Is it possible to do the same as this using MKMapView or IOS native code?
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.
Use MapKit to give your app a sense of place with maps and location information. You can use the MapKit framework to: Embed maps directly into your app's windows and views. Add annotations and overlays to a map to call out points of interest.
The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects MapKit uses to manage the annotation data and the view objects for presenting that data on the map.
Open Main. storyboard and, from the Object library, drag a Map Kit View into the middle of the scene. Constrain the Map View to the super view (not the Safe Area), setting 0 on all edges, so it stretches throughout the Safe Area of notched devices. Build and run.
Blend modes, overlay improvements, and more MapKit is Apple's framework for showing Apple Maps on your application. It helps developers provide navigation support and on-place guidance and offers users an area on the map.
For get detailed information including the address of the POI I think you can do this in two steps:
Get the coordinate of your POI
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With