MapKit problems with annotations - iphone

Ok, so I've got some issues with my MapKit annotations.
First of all, I want a callout for each annotation. I can't find out how to do this at all! :( I have two NSStrings (name of the place and a short description). Then I need to be able to log the click on the callout - so I can launch a disclosure view.
Secondly I want to change the view for the user location annotation.
At the moment all annotations are set to the "default" pin annotation view by way of this code:
- (MKAnnotationView *) mapView:(MKMapView *)myMapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"currentloc"];
annView.animatesDrop=TRUE;
return annView;
}
I would prefer to have the user location annotation set to the default blue pulsing circle thing, but at least I want to be able to change the pinColor property to a different color, so the user can distinguish between their own location and the results of their search.
I hope somebody can help me.
Thank you.

I think you should consider using showsUserLocation to depict your users location - it's the standard UI for the platform and helps people get a consistent experience across apps. Sure you can come up with some custom annotation for user location but why re-invent what people are used to seeing on the maps app and on many 3rd party apps?
You should take the time to review Apple's code samples for MapKit everything you need to do is there. This one in particular is a good starting point for you:
http://developer.apple.com/iphone/prerelease/library/samplecode/MapCallouts/Introduction/Intro.html

hmm... the problem was i didn't know which annotation was the one being used by current location. Its ok - I've found it now. Something like if(annotation == mapView.userlocation){ return nil; } or similar. :) Thanks for your help though

Related

iphone Detect selected MKPinAnnotation in a MapView

I have a custom MKPinAnnotation in which I have added a couple of peroperties , like the Id of the object and the type. What I want is when someone selects a pin in the MapView to detect which pin is selected and get that data.
And Show a button on its view to use that data in the button's action.
Can anyone help with this? I can't find how to detect if (and which) an annotation is selected.
There is already a built in method to take care of this situation for you. You need to use the method below. The view.annotation is the annotation that was tapped.
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"The annotation tapped is: %#", view.annotation.title);
}
Edit: It can be found here, the API is your friend.
https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/doc/uid/TP40008204

Programmatically move the pin in digdog MapKitDragAndDrop framework

I have the digdog MapKitDragAndDrop in one my projects to achieve drag and drop pins. Im also allowing the user to search for location based on the address.
When the user searched and found his location coordinates, i want the pin to move to that location. Animation etc is not mandatory
I not able to figure out how to move the pin manually.
Just provide a new set of coordinates for your annotation, remove it and put it back in the map view's annotations. Some code from you would help be precise.
But basically the idea is that you remove the annotation from the map view and then put it back again, with the good coordinates. As a DDAnnotation is a MKPlacemark, that shouldn't be too hard.
It would look like:
- (void)annotation:(DDAnnotation*)annotation hasNewCoordinates:(CLLocation)location{
[_mapView removeAnnotation:annotation];
annotation._coordinate = location;
[_mapView addAnnotation: annotation];
}
Of course untested.

How to present Blue circle of current location in MKMapView iphone

I have an maps application in which I show the points of interest in the map using pins. I want to represent the current location with the blue circle which is shown in Google maps. Is there any way we can add it. Can any one please help me with this. I really appreciate your time.
Thanks
You can get this by specifying nil in the appropriate delegate method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation {
if (annotation == mapView.userLocation) {
return nil;
}
}
This should cause MKMapView to use the default, which should be the blue circle.
You should set the setShowsUserLocation: property of your map view to YES. This can be done programmatically or in Interface Builder. Be careful, as I believe the simulator still shows the user location in Cupertino, CA.
Also, if you continue tracking the user and their movements, the blue indicator will continue to move as they do.

Description to current location?

Is there a way to display some text on the blue dot alike to an annotation? Right now, it only shows "current location" when the user tap on it. I want it to act somewhat like an annotation to display current address. Where there's a title and subtitle property available to use.
I thought of replacing it with my own annotation but can't figure the way to do so.
Please advise.
Thank you
You should be able to do it by implementing mapView:didSelectAnnotationView: in MKMapView Delegate...
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if(view.annotation = mapView.userLocation){
//reverse geocode mapview.userLocation.coordinate to get address
//then set title
}
}

How to recenter map in iPhone app on zoom in/out using MKMapView

I am developing an iPhone application in which I need to show an image at a specific Latitude & Longitude on a Map. The requirement is - Even if the user zooms in or out on this map screen, the map control should automatically center itself after the zoom, to the same Lat & Long. I am using MKMapView.
I have tried to go through all available documentation. However, I could not come across any callback or other method that will allow me to achieve the objective.
One alternative is to handle touch events. However, I find that as a very complicated solution. And I hope that a simpler alternative exists. Any ideas on the above?
Can you please help? Any example will be appreciated.
Implement MKMapViewDelegate and then try this:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[mapView setCenterCoordinate:locationManager.coordinate animated:NO];
}
Replace locationManager with whatever the name of your CLLocationManager is.