I'm adding annotations to an MkMapView and am using a custom image to do so. My custom image is box shaped with a little triangular arrow that's supposed to be right on the place that's being annotated. It seems like MapView by default annotates using the geometric center of the image. What's the best way to design around this problem? Manually moving the icon? Creating the icon in a specific way?
Here's the Apple docs for MKAnnotationView's centerOffset property:
By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in pixels. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.
Related
MKAnnotationViews documentation says
Managing Collisions Between Annotation Views
var collisionMode: MKAnnotationView.CollisionMode
The collision mode to use when interpreting the collision frame rectangle.
enum MKAnnotationView.CollisionMode
Constants indicating how to interpret the collision frame rectangle of an annotation view.
I'd like to debug some collision behaviour that I don't understand.
So how do I get the collision frame rectangle that is referenced in the MapKit documentation? I'll probably try to draw this rectangle for visual debugging.
How do I set the collision frame rectangle? Maybe not directly, but which of the many involved views determines this rectangle?
This is the only reference of this term that I found in MapKit
Edit
Is this collision frame rectangle only used to make clusters or is it also used to hide the cluster with a lower display priority?
I have two AnnotationViews visually drawn on top of each other. One has displayPriority = .required, one has displayPriority = .defaultHigh. One should disappear. But where are their collision frame rectangles? Do they really overlap?
I found an explanation here. It says:
collisionMode: An MKAnnotationView.CollisionMode. Two annotation views with the same clusteringIdentifier will be replaced by a cluster annotation if the map is zoomed out so far that they collide.
But what constitutes a collision between two annotation views? To know that, we need a collision edge. It might be:
.rectangle: The edge is the view’s frame.
.circle: The edge is the largest circle inscribable in and centered within the view’s frame.
EDIT:
The docs say: The most efficient way to provide the content for an annotation view is to set its image property. The annotation view sizes itself automatically to the image you specify and draws that image for its contents. Additionally, there are other properties that may influence the frame property. So it is this automatically adjusted framethat determines the collision frame.
I'm trying to create an MKCircle overlay on a map, however I would like the size of the circle on the screen to remain constant as the user zooms.
So as the user zooms in, the radius gets smaller and as the user zooms out, the radius gets larger.
I'm working in Swift 3. Is there a specific MapKit method I should be using to accomplish this? I know there is an option to use an image of a circle as an annotation, however I want to dynamically change the color of the circle.
In other words, I want the MKCircle to scale the same way an MKPolyline scales as you zoom in and out
So as the user zooms in, the radius gets smaller and as the user zooms out, the radius gets larger
An MKCircle would presumably be part of an overlay (MKOverlay). An overlay works by simulating drawing on the earth itself. Thus, the drawing changes with the zoom level.
So if you don't want that to happen, don't use an MKOverlay. You could, for example, just make a normal view that displays a circle and lay it in front of the map view. Or you could use an annotation instead (MKAnnotation); an annotation's image does not change size as the map is zoomed.
I'm finding that any annotation image marker that is above some undefined size does not align the bottom of the marker to the coordinates. I've been unable to locate any documentation on it. Why is this and can it be fixed?
The coordinates are for the middle of Manhattan, New York City. Note how the green border sits well into the ocean. The coordinates are definitely right. When I use a different smaller image the annotation sits correctly and when I zoom in it sits correctly. But at anything above a 10.0 zoom level it does not sit correctly.
The coordinate will align with the center of the custom image. Since there currently isn't a way to specify a custom offset, you will need an image with its bottom 50% empty so that its center aligns with the coordinate on the map when placed.
I want to draw a rectangle on a chart and have it move with the rest of the chart. However, it stays where it was originally rendered in pixel coordinates.
I would have thought there would be a way to add annotations such as this in world coordinates rather than screen coordinates, but I was not able to find a way. Is such a thing possible?
Assuming I am stuck with annotating in screen coordinates, what event(s) do I need to handle to redraw the rectangle when the user zooms or scrolls?
Simple example:
chart.renderer.rect(chart.xAxis[0].toPixels(1432897200000),chart.yAxis[0].toPixels(1.09674),14,14, 0)
http://jsfiddle.net/bz3t79p5/
Also, I have had no luck with using axis.toPixels() for setting the rectangle's width and height. I was getting values that were way out of whack. Is there a trick to converting width and height from world coordinates to pixels?
I would like to have a annotation in the center of the map, that does not move when the region is changed. That is, when one moves the map, the annotation stays in the center regardless. I have implemented this using NStimer, assigning the map center coordinate to the annotation every .001 seconds, however this is very choppy and doesn't look smooth.
I realize that I need to use an Overlay than convert the overlay annotation to coordinates on the map.
Pretty much it would look like what Uber has.
THe other solutions for this that I have seen have not used a normal annotation. Instead they put another view over the top of the map with the annotation image in the middle. It doesn't matter what happens to the map the view stays centered on the screen and if you do ever need to interact with it, you just ask the map what the center coordinate is at that time.
You can get the code from the following link:
https://github.com/scottrhoyt/CenterPinMapViewController