Why when I load my pin annotation in map, my pin annotations have different number shadow? Some have no shadows and some have many shadows.
I receive the data for pin from the firebase.
How to remove shadow or how to make a small shadow in all pin?
Check image
The darker shadow means you have multiple pins in the same location. There are two main causes for this and depending on the reason, there are two ways to solve this:
1. The data contains multiple elements with the same location.
Consider using clustering, which will display the number of annotations in the location. This will be a lot easier for the user to understand than a darker shadow. :)
Here's a tutorial from Apple: Decluttering a Map with MapKit Annotation Clustering
2. You forgot to erase the annotations before adding them again.
Remove the annotations before adding them to the map again, for example when you're refreshing the view.
mapView.removeAnnotations(annotationsToRemove) where annotationsToRemove is an array containing the specific annotations you need to remove.
Or, if you want to add all the annotations again, you can remove all the annotations with
mapView.removeAnnotations(mapView.annotations)
Related
I am using a MKTileOverlayRenderer to render my own tiles with MapKit. In areas where my tiles don't cover, the empty grid is shown, which is exactly what I'm looking for. However, all names of places (labels of landmarks) get also shown. I would like to hide these to provide an empty space beyond the confines of my tiles.
This is how I am initializing the mapView:
let overlay = MapOverlay(map: map)
// MapOverlay is my own subclass of MKTileOverlay, map is a Swift struct including url scheme to retrieve the tiles
overlay.canReplaceMapContent = true
// I intend to have empty content beyond my tiles
tileRenderer = MKTileOverlayRenderer(tileOverlay: overlay)
mapView.addOverlay(overlay, level: .aboveLabels)
// I want my tiles to be laid over all other content
This is how it shows around the borders of my tiles in MapKit:
I know it's possible to use a placeholder tile for areas beyond the region of interest, which would cover, in principle, the empty grid and the landmark label names. This is problematic though for 2 reasons:
When zooming in/out or panning, and for the split second it takes to load the tile, it shows the content below, which is disorienting
the placeholder tile doesn't blend seamlessly with the provided tiles of the region of interest, which leaves gaps through which you can still see the empty grid and the landmark label names
For these reasons, I chose to use a transparent placeholder tile.
Is there a way to hide the landmark label names?
I couldn't find a way to prevent MapKit from showing the label names for landmarks (and the canReplaceMapContent property hides the map content but not the labels), but I figured out why covering beyond the region of interest was leaving gaps: the original tiles had transparency around the edges of the region of interest.
A way to cover the landmark label names is to provide solid color in the edges of the region of interest in the generated tiles, and use a placeholder tile with the same solid color for areas beyond the region of interest. Therefore, no code changes needed, just to regenerate the tiles with solid color around the edges.
This still has the issue of small glimpses through the map when zooming, panning, which is not great, but I can't see no way around that.
Does exist any way to remove GMSPolygons from GMSMapView?
It does not seem to exist a property of GMSMapView containing them (as GMSPlolyLines), should I clear the map and render all again?
thanks
When you create the GMSPolygon you set its map property to add it to the map. To remove it from the map, set its map property to nil. This means you need to keep your own record of the polygons which you've added to the map, which you want to be able to remove later.
For example mySavedPolygon.map = nil
From google maps document
clear Clears all markup that has been added to the map, including markers, polylines and ground overlays.
So you just use
[mapView clear];
This should clear the polygons.
This has been updated, has I am using the clear function, and was looking for a way to keep the polygons while using this.
I've just confirmed against the Google Maps API Reference.
Clears all markup that has been added to the map, including markers, polylines and ground overlays.
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view.html#a28e6b8aeb7c8dc9025dc001f2a5d2c9b
I have map view and many pins on it.
When the map view is zoomed out, I group overlapping pins into 1 (and show in label total count of pins in it).
But what to do, if map view is max zoomed in, and pins are still overlapped?
How can I shift them while they do not overlap each other ?
Something like this:
Or is there another solution?
In a slightly different solution to the same problem, the demo in the WWDC 2011 #111 - Visualizing Information Geographically with MapKit video (the demo is a little more than 18 min into the video) illustrates an example of how you can prevent overlapping annotations (including some nice animation revealing and hiding more detailed annotations as you zoom in and out).
What they do is to break the mapview into a grid of a particular size (I think they use 60px), and if they are too close, they pick one for that grid and hide the others. They also do a graceful hiding of the annotations as you zoom out (so you can see the annotations that are being hidden fly into the visible annotation for that group). As you zoom in the annotations are unhidden, you see it fly out of the one central annotation for that grid.
I need to draw many (hundreds to thousands) of square overlays on a map. The positions and sizes of these overlays stay constant. I think that I can speed up rendering by combining these square overlays into a single overlay so drawMapRect only needs to be called once. Is this possible?
In my case, removing overlays is not an option. A way I found to drastically improve performance was to have my overlay class store an array of the square overlays. Then in my overlayView's drawMapRect method, I looped over the array to draw all the overlays. Something very similar is done in the HazardMap Apple Developer Example. See drawMapRect in HazardMapView.m
I had similar problem for MKAnnotation.
And I found following link:
http://www.fiveminutes.eu/having-fun-with-ios-map-kit-grouping-annotations/
Iterate annotation list and calculate a distance of two annotation's coordinate.
If there's nearby annotation exist, remove it from the list.
I think this approach can be applicable to MKOverlays too.
I am developing an application which will show where trains are at any given time. It will receive gpx-data from the trains to get their location.
Is there any way to animate a sprite moving along a restricted line in a mapview? In my example, a train moving along a trainroute.
I have drawn the trainroutes as polyline in an overlay, and the train is an annotation.
I ended up making a visible overlay, then making a separate array out of the same coordinates.
To simulate the movement, the MKAnnotations uses 'setCoordinate' while iterating the array, which in fact is the same as the overlay.
This made the annotations look like they moved atop of a restricted overlay.