Custom map regions for displaying limited annotations

Can anyone tell me (or point me to a resource for) how to let a user (1) draw a custom region on the map, (2) display only the annotations within that region? This is what Zillow does in their app. Thanks!!

When you say “Draw a custom map region”, do you mean display a specific region in your map view? Or do you mean that you want to draw some sort of an overlay over a specific region? (I have not used Zillow - so not sure how Zillow does it …)

If you just need to display a custom region, then all you need to do is look at the MKMapView documentation:

The method you are looking for is: setRegion(_:animated:) for setting the region, or perhaps even setVisibleMapRect(_:animated:).

If you want the annotations for a specific region to display, you can also simply call showAnnotations(_:animated:). You pass an array of annotations to the method and the map view will reset the displayed region to cover only the area taken up by the passed in annotations array.

This topic was automatically closed after 166 days. New replies are no longer allowed.