How to remove map Places and annotations from MKMapKit in Objective c
Asked Answered
P

3

5

Hi i have an MapView in My Project i need to remove all the labels Annotations, places from MapView. Looks like Plain mapView

i tried the Following Code its working fine but still i getting some building details, Street names and all i want that also to be removed only User Location Can be Visible

here is the code:

[mapView setShowsPointsOfInterest:NO];

the above code working fine and removed default location icons from mapKit but not removing all Icons and Label, how to remove all default icons and label names from MapKit

Parka answered 18/6, 2018 at 9:9 Comment(2)
Possible duplicate of How to delete all Annotations on a MKMapViewSulfite
I think you want to style the map to be a lot more bare than it is, here are some solutions for that: https://mcmap.net/q/800591/-custom-map-style-in-mapkitShaunda
D
15

starting with iOS 11, you can set

mapView.mapType = .mutedStandard

This removes distracting details from the map.

Apple uses this type of map, when they want to emphasise a transit route and everything else should be in the background without distracting.

Starting with iOS 13 you have even more fine grained control:

Using MKMapKit.pointOfInterestFilter you can include or exclude specific categories of points of interest.

So if you're making an App 'Best restaurants in my city', your app has its own restaurant annotations, you remove the restaurant category from Apple's point of interests, but all other POI categories are just fine for you.

https://developer.apple.com/documentation/mapkit/mkmapview/3143417-pointofinterestfilter?language=objc

Starting with iOS 16 most APIs described above are deprecated, but the ideas remain the same.

Now you set MKMapView.preferredConfiguration to a subclass of class MKMapConfiguration. These subclasses are

  • MKStandardMapConfiguration
  • MKHybridMapConfiguration
  • MKImageryMapConfiguration

Each of these classes have exactly those parameters that make sense for the type of map.

For example, MKImageryMapConfiguration shows no POIS and no roads, so it makes no sense that this class has parameters like pointOfInterestFilter or showsTraffic.

Classes MKStandardMapConfiguration and MKHybridMapConfiguration now have a parameter pointOfInterestFilter that has been in MKMapKit.pointOfInterestFilter in earlier iOS versions.

Old deprecated mapView.mapType = .mutedStandard is now init parameter emphasisStyle of class MKStandardMapConfiguration

P.S. Please also have a look at the other answer of @Grimxn. Bringing your own overlay is much effort but a valid alternative.

Dirichlet answered 17/11, 2018 at 11:22 Comment(0)
T
7

In case anyone is coming back to this, as of writing this, if you want literally just a map and road names, no points of interest, just use

mapView.pointOfInterestFilter = .excludingAll
Thyroid answered 6/3, 2021 at 6:46 Comment(0)
C
4

It seems to be a bit of a kludge.

Firstly, you replace the map with an overlay of your own...

self.mapView.insertOverlay(underlay, at: 0, level: MKOverlayLevel.aboveLabels)

This can be anything. If you want to use Google Maps, or Open Street Map, you can, like this:

let url = "http://mt0.google.com/vt/x={x}&y={y}&z={z}"
//let url = "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
let underlay = MKTileOverlay(urlTemplate: url)
underlay.canReplaceMapContent = true

alternatively, if you just want blank, give it a default layer:

let underlay = MKTileOverlay()
underlay.canReplaceMapContent = true

The parameter level: allows you to specify whether your background obscures just their background map, or the background & roads or the background & labels, but NOT above everything. The documentation says:

MKOverlayLevel.aboveLabels

case aboveLabels = 1

Place the overlay above map labels, shields, or point-of-interest icons but below annotations and 3D projections of buildings.

I can't get that to work for the default MKTileOverlay() - it seems to do the same as the alternative .aboveRoads - i.e. it hides all of the map including roads, but not labels. When you specify one of the external overlays (e.g. google) - they DO replace the labels. Probably a bug, so the final step, to completely obliterate the labels is

self.mapView.mapType = .satellite

This removes the labels, and your overlay is hiding the satellite map. Not neat, but not difficult, either.

Chaffin answered 11/9, 2019 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.