Custom annotation view using MKCircle - iphone

I am trying to make a custom view for a custom MKAnnotation I have. What I want is a solid circle with a number inside, and a colour depending on what the value of that number is. The number's value will be taken from my custom MKAnnotation class. I currently have the annotation view as a map pin, and I have a callout method assigned to it etc. so I want my new view to function the same as this pin view. How would I go about this? I can't seem to find anything that teaches me how to do this: would I have to create the circle as an overlay and handle the drawing in the map view controller?

Related

How to place a view next to an MKRoute in a MapKit app

I have an app that is using MapKit's MKRoute. I want to place a UIView on the route on the map, similar to how Apple annotates routes in Maps with an estimated travel time popover:
http://www.siprog2.com/pjx/fichiers/mkroute.jpg
You can use MKAnnotation to annotate a specific coordinate point on your route. Your MKMapView's delegate will then be asked to return an MKAnnotationView if your annotation is in the currently visible area of the map.
Apple has sample code for adding custom annotation views to a map (it's not using a route, but all you need to change is annotate a point on your route).

string under Map Kit pin (mkannotationview image)

I am trying to set names under pins that are on a map. Each name should be specific.
I am not using default pins, hence each pin is a specific image.
I was thinking of generating some kind of image that would present the image of the pin and the name as a label under it. Then append the whole thing as the image of the mkannotationview. But this looks like a mess to me.
Is there a way I could possibly append a label under a mkannotationview?
Or should a make a custom mkannotationview?
Thank you for your time.
Starting with iOS 11, if you subclass MKMarkerAnnotationView, you get those texts below the bubble for free, including collition detections: the text is sometimes rendered more left or right, depending where there is some space left on the map.
The MKAnnotationView class is a subclass of UIView, so you should be able to subclass it fairly easily.
I would probably create a custom subclass, and have my subclass add a label as a subview of the MKAnnotationView. You might need to adjust the frame of the view to make room for the label you're adding.

Multiple Annotations ( MKAnnotationView ) in the same location Coordinates

Hi I am trying to implement Annotations grouping and animation if the user touch.
I did look a the different cluster Library solution but this wont work for my because I have multiple Annotations in the same Coordinates.
So this is what I want to do
1- I identify where there are multiple Annotations in the same place (Coordinates)?
how can implement this ? find the annotations in the same coordinates and make a new group annotation ?
2- change the colour of that Annotation (to let the user know)
I can do this on this method
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation;
3- if the user touch the annotations in that group , annotations will move in a circle around their location.
So far I have all my annotation on the map some have a very dark shadow.
I want to focus in the first task now - grouping
I am not asking for code example I can do that I just need help figuring out what methods to use to implement the task .
Thanks for your help.
I ended up implementing this code from StormID
Handling MKMapView Annotation Pins on the Same Coordinate
I have to make some changes but it works great.
To get rid of the dark shadow, which is caused by stacked annotation views, I would change your mapView:viewForAnnotation: to recognize when the passed annotation has the same coordinates as another and only return a view (of a different color) for one of those annotations.
Then, for your animation, upon touch of the grouped annotation, I would set mapView.scrollEnabled = mapView.zoomEnabled = NO temporarily for simplicity's sake, hide the group annotation, and create an overlay with animations of the individual annotations yourself. Upon another touch, animate them back to the center, remove them and the overlay, and unhide the grouped annotation and re-enable the map.

How to designed a correct MVC on iOS?

I have a project where I want to display overlays to locate people on a map. I have difficulties to follow the MVC pattern since I've never practice it.
In a database, I'll save a position (in map coordinates) and the image to identify one person (the image of the overlay).
If 2 or more are at the same position, they are grouped under another "group" overlay. When an overlay is touched, I want to display different information, depending of its type ("group" or "single").
Here is my problem : I obviously need to subclass an Overlay superclass, which have the properties position and image, to redefined the overlayTouched: method. But this code his typically a View code of the MVC pattern, but the overlay is a Model object since it will be saved, so i'm confused.
How should I designed this ?
You should not subclass Overlay to add touch events to it, instead create a new UIView, YourNewView
This YourNewView will "has a" instance of Overlay, and it will delegate all its method that are required from the model to Overlay
For example. if you have a touchesEnded in your YourNewView and you want it to save the overlay to the DB, you would do
//in touchesEnded
[self.overlay saveToDb];
And so on, all the calls will be forwarded to the Overlay Class

Change Custom annotation Label without removing it from Map in iPhone

I am diplaying a Custom annotation in the center of the map. Which continues need to update its label how far is it from the center of the map.
P.S. Center of the map means the centre of the visible region in the map.
So by default my annotation is in the center of the map with label 0 then when I move the map it must update itself.
Currently on each move I am removing the annotation and adding the annotation with updated text. But its not the correct way..
Kindly help.... Thanks in advance....
I'd add a UIView with the label on it on the view that contains map right after adding map view. The size of this new view should be the same to size of the map. The tricky part is handling touches on it and then transferring them to the map view. You can dig into this tutorial. It is not map view but web view, nevertheless principles are the same.
If you choose that way you don't have to add this label as an annotation.