iPhone - Replace GoogleMap MapKit user's direction blue dot with spinning arrow - iphone

How may I show an arrow that shows the users direction instead (over ?) the existing blue dot in the MapKit on a GoogleMap view ?

From the documentation of the mapView:viewForAnnotation: delegate method:
If the object in the annotation parameter is an instance of the MKUserLocation class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil.
So you should do just that. Check the class of the annotation for MKUserLocation and in case of a successful match, return a custom view. You must take care to update this view yourself whenever the user's heading changes.

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).

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

MKPinAnnotationView - different actions in different Pins

I have a question about the MKPinAnnotationView. First of all I entered coordinates of the pins and after that called the viewForAnnotation to build them and also add them the a right button.
But my question is how can I select different actions for those pins?
When I look for the button tag in NSLog, it always shows 0 for every pin so I can't make it with tags.
Here is the code of the button if it means something:
for (int i=0;i<=[[mapview annotations]count];i++) {
pinView.tag = i ;
rightButton.tag=i;
}
You don't need to (and should not) use tags.
Instead, in the action method, you can determine which annotation was selected and then execute different logic based on that.
You don't even need to create your own action method. When a callout button is tapped, the map view will call its calloutAccessoryControlTapped delegate method which gives you a reference to the annotation (ie. view.annotation). If you decide to use the delegate method, remove the addTarget from viewForAnnotation and just implement the delegate method.
If you want to use your own action method for some reason, you can determine which annotation was selected by looking at the map view's selectedAnnotations property. The selected annotation will be at index 0 (be sure to first check that the array's count is not zero).
For sample code of all the above, see this question:
How to keep data associated with MKAnnotation from being lost after a callout pops up and user taps disclosure button?

Custom annotation view using MKCircle

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?