Update label text from annotation title - ios

Im trying to update a label in the next view with an annotations title on segue, Im not sure how to do this, but working on the lines of this. Any suggestion or does this need to be done where the annotation is created?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushShare"])
{
ShareViewController *vc = (ShareViewController *)segue.destinationViewController;
[vc fromLabel.text = StartAnnotation.title];
}
}
Update
The annotation is created when a button is clicked, a pin is dropped on the user location and the annotation title displays the address, Iv tried updating a label in the same view with the title but having trouble with that aswell.
code for creating the annotation
CLLocationCoordinate2D theCoordinate = {_map.userLocation.location.coordinate.latitude,_map.userLocation.location.coordinate.longitude};
CLLocation *currentLocation = [[CLLocation alloc]
initWithLatitude:_map.userLocation.location.coordinate.latitude
longitude:_map.userLocation.location.coordinate.longitude];
NSLog(#"self.geocoder=%#", self.geocoder);
[self.geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemark, NSError *error) {
NSString *address = #"Address unknown";
NSLog(#"geocoder error=%#", error);
if (placemark.count > 0)
{
CLPlacemark *topResult = [placemark objectAtIndex:0];
address = [NSString stringWithFormat:#"%# %# %# %#", topResult.subThoroughfare, topResult.thoroughfare, topResult.subLocality, topResult.locality];
}
StartAnnotation *startPoint = [[StartAnnotation alloc]init];
startPoint.coordinate = theCoordinate;
startPoint.title = address;
startPoint.subtitle = #"Start Point";
[self.map addAnnotation:startPoint];
[self.map selectAnnotation:startPoint animated:YES];
}];
//e.g. fromLabel.text = StartAnnotation.title;

You can handle didSelectAnnotationView to detect when a user tapped on your MKAnnotationView, like in this example:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[mapView deselectAnnotation:view.annotation animated:YES];
[self performSegueWithIdentifier:YOUR_SEGUE_ID
sender:view];
}
Then in prepareForSegue extract the title of the annotation and use it:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:YOUR_SEGUE_ID])
{
UIView *annotationView = (UIView *)sender;
ShareViewController *vc = (ShareViewController *)segue.destinationViewController;
vc.textToSetOnTheLabel = annotationView.annotation.title;
}
}

Related

Annotations on Map at lat/long (0,0) on device but located right in simulator

in my first iOS app I've got a map displaying annotations for several locations. It works perfectly in the simulator and looks like this:
But on all devices the annotations are not located right. They are all placed at latitude 0 and longitude 0.
Do you have any ideas?
Here is my Source Code:
MapViewController.m
//
// MapViewController.m
//
#import "MapViewController.h"
#import "AppDelegate.h"
#import "Location.h"
#import <MapKit/MapKit.h>
#import "Reachability.h"
#import "MyAnnotation.h"
#interface MapViewController ()
#end
#implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.mapView.delegate = self;
//User location
self.locationManager = [[CLLocationManager alloc]init];
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
[self loadOfflineMap];
[self addAnnotations:[(AppDelegate *)[[UIApplication sharedApplication] delegate] locations]];
//Set initial region
MKCoordinateRegion region = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(53.868223, 10.689060), 3000, 3000)];
//Set initial locatoin if one is set
if(self.initialLocationName != nil){
for (id<MKAnnotation> annotation in [self.mapView annotations]) {
if([[annotation title] isEqualToString:self.initialLocationName]){
[self.mapView selectAnnotation:annotation animated:YES];
region = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance([annotation coordinate], 500, 500)];
}
}
}
[self.mapView setRegion:region animated:YES];
//Layout stuff
self.locationName.font = [UIFont fontWithName:#"CenturyGothic" size:self.locationName.font.pointSize];
self.locationAddress.font = [UIFont fontWithName:#"CenturyGothic" size:self.locationAddress.font.pointSize];
}
-(void)addAnnotations:(NSMutableArray *)locations{
self.locationNameToAnnotation = [[NSMutableDictionary alloc] init];
for(Location *location in locations){
MyAnnotation *annotation = [[MyAnnotation alloc] initWithTitle:location.name AndCoordinate:CLLocationCoordinate2DMake([location.latitude doubleValue], [location.longitude doubleValue])];
[self.locationNameToAnnotation setObject:annotation forKey:location.name];
[self.mapView addAnnotation:annotation];
}
}
-(void)mapView:(MKMapView * )mapView didSelectAnnotationView:(MKAnnotationView * )view{
for(NSString *locationName in self.locationNameToAnnotation){
if([locationName isEqualToString:view.annotation.title]){
Location *location = [Location getLocationFromLocations:[(AppDelegate *)[[UIApplication sharedApplication] delegate] locations] byName:locationName];
self.locationName.text = location.name;
self.locationAddress.text = location.address;
}
}
self.locationInfoView.hidden = NO;
[self.mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
}
-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view{
self.locationInfoView.hidden = YES;
}
-(void)loadOfflineMap{
self.mapView.delegate = self;
NSString *baseURL = [[[NSBundle mainBundle] bundleURL] absoluteString];
NSString *template = [baseURL stringByAppendingString:#"{x}-{y}.jpg"];
self.overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
self.overlay.canReplaceMapContent = YES;
self.overlay.minimumZ = 12;
self.overlay.maximumZ = 19;
[self.mapView addOverlay:self.overlay level:MKOverlayLevelAboveLabels];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
- (IBAction)mapTypeChanged:(UISegmentedControl *)sender {
if(sender.selectedSegmentIndex == 1){
if([self checkIntetnetConnection] == YES){
[self.mapView removeOverlay:self.overlay];
}else{
sender.selectedSegmentIndex = 0;
}
}else if(sender.selectedSegmentIndex == 0){
[self.mapView addOverlay:self.overlay level:MKOverlayLevelAboveLabels];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)checkIntetnetConnection{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
//NSLog(#"There IS NO internet connection");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Internet" message:#"Sorry, please turn on your internet to access the online map" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
return NO;
} else {
//NSLog(#"There IS internet connection");
return YES;
}
}
#end
MyAnnotation.m
//
// MyAnnotation.m
//
#import "MyAnnotation.h"
#implementation MyAnnotation
#synthesize coordinate=_coordinate;
#synthesize title=_title;
-(id) initWithTitle:(NSString *) title AndCoordinate:(CLLocationCoordinate2D)coordinate
{
self = [super init];
_title = title;
_coordinate = coordinate;
return self;
}
#end
Edit 1
Locations Array Parsing from JSON, which works fine:
-(void)createLocations:(NSDictionary *)jsonLocations{
self.locations = [[NSMutableArray alloc] init];
for(NSDictionary *jsonLocation in jsonLocations){
Location *location = [[Location alloc] init];
[location setName:jsonLocation[#"name"]];
[location setId:jsonLocation[#"id"]];
[location setLatitude:[self getNumberFromString:jsonLocation[#"latitude"]]];
[location setLongitude:[self getNumberFromString:jsonLocation[#"longitude"]]];
[location setZoomlevel:jsonLocation[#"zoomlevel"]];
[location setAddress:jsonLocation[#"address"]];
[self.locations addObject:location];
}
}
I'd really appreciate all ideas. Probably it's an easy question but since I'm new to iOS Development I'm quite frustrated right now.
Cheers Thomas!

Pass Data to another view controller

I have a two view controllers (DatePickerViewController and RouteHistoryViewController). I also have the server response in DatePickerViewController. How can I pass that response to the RouteHitoryViewController. The RouteHistoryViewController has a map view.
Here is the code DatePicker.m :
#import "DatePickerViewController.h"
#import "MapAnnotation.h"
#interface DatePickerViewController ()
#end
#implementation DatePickerViewController
{
//#define URL #"http://140e3087.ngrok.com"
#define URL3 #"http://784effb4.ngrok.com/bustracking/json/student/route_history"
NSString *formatedDate;
NSString *lat;
NSString *longi;
NSString *server_created_date;
}
#synthesize appDelagate,datePicker;
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(#"%#", appDelegate);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd HH:mm"];
formatedDate = [dateFormatter stringFromDate:self.datePicker.date];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sendPicker:(id)sender;
{
[self sendDataToServer : #"GET"];
// NSLog(#"%#", formatedDate);
//self.selectedDate.text =formatedDate;
}
-(void) sendDataToServer : (NSString *) method{
NSString *beaconiD = #"EC112729B51B";
NSString *trackerID = #"e61078a67e4233ad";//appDelagate.tracker_id;
NSString *date = formatedDate;
NSMutableURLRequest *request = nil;
NSString *getURL = [NSString stringWithFormat:#"%#?beacon_id=%#&tracker_id=%#&date=%#", URL3, beaconiD, trackerID, date];
getURL = [getURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString: getURL];
request = [NSMutableURLRequest requestWithURL:url];
NSLog(#"link: %#", getURL);
[request setHTTPMethod:#"GET"];
[request addValue: #"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(#"connection: %#", connection);
if( connection )
{
mutData = [NSMutableData new];
}
else
{
NSLog (#"NO_CONNECTION");
return;
}
}
#pragma mark NSURLConnection delegates
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response
{
[mutData setLength:0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[mutData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog (#"NO_CONNECTION");
return;
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// NSString *jsonresultString =[jsonresultDict objectForKey:#"result"];
// NSLog(#"%#", jsonresultString);
// //serverResponse.text = jsonresultString;
NSError *error = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:mutData options:kNilOptions error:&error];
NSArray *fetchedArr = [json objectForKey:#"result"];
for (NSDictionary *user in fetchedArr)
{
lat = [user objectForKey:#"latitude"];
longi = [user objectForKey:#"longitude"];
server_created_date = [user objectForKey:#"server_created_date"];
NSLog(#"Item date&time : %#", server_created_date);
NSLog(#"Item longitude : %#", longi);
NSLog(#"Item latitude : %#", lat);
}
}
Here is the code RouteHistory.m:
#import "RouteHistoryViewController.h"
#import "MapAnnotation.h"
#interface RouteHistoryViewController ()
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#end
#implementation RouteHistoryViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
//[self.mapView removeAnnotations:self.mapView.annotations];
MapAnnotation *mapPoint = [[MapAnnotation alloc] init];
mapPoint.coordinate = CLLocationCoordinate2DMake([self.appDelagate.latitude doubleValue], [self.appDelagate.longitude doubleValue]);
mapPoint.title = self.appDelagate.name;
mapPoint.time = self.appDelagate.server_created_date;
mapPoint.mapimage = self.appDelagate.image;
// Add it to the map view
[self.mapView addAnnotation:mapPoint];
// Zoom to a region around the pin
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(mapPoint.coordinate, 500, 500);
[self.mapView setRegion:region];
//testing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receiveTestNotification:)
name:#"MapUpdate"
object:nil];
// Do any additional setup after loading the view.
}
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *view = nil;
static NSString *reuseIdentifier = #"MapAnnotation";
// Return a MKPinAnnotationView with a simple accessory button
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
if(!view)
{
view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
view.canShowCallout = YES;
view.animatesDrop = YES;
}
return view;
}
datepicker to route history using prepareforsegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier]isEqualToString:#"b"])
{
RouteHistoryViewController *rh = segue.destinationViewController;
NSLog(#"%#", rh);
}
}
In first view controller inside connectionDidFinishLoading after this line
NSArray *fetchedArr = [json objectForKey:#"result"];
add the following two lines
_responseFromServer = fetchedArr;
[self performSegueWithIdentifier:#"segueToRouteHistory" sender:self];
and then add this method in your first View Controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"segueToRouteHistory"])
{
RouteHistoryViewController *routeHistoryController = [segue segueToRouteHistory];
[routeHistoryController setFetchedArray:_responseFromServer];
}
}
In your First View Controller .h file add this
#property NSArray *responseFromServer;
Now We have assigned the Response array received from server to a object in your destination view controller.
Don't forget to add
#property NSArray *fetchedArray;
inside your Second ViewController's .h file
Now you can access this array in second view controller.
PS: Do not forget to give segue from storyboard from first view controller to second view controller and name the Segue Identifier as "segueToRouteHistory"

How to send facebook user information into another view controller?

I'm trying to save the username and user email after a user logs into my app through facebook.
I have set up a segue to pass the info from the login view controller to the view controller where I plan to save the user strings and some other strings into my sqlite database.
When I do run my app in the destination view controller and try to insert all the data into sqlite, I am thrown an error saying the userName and the userEmail are nil strings, so my data is not being saved. I have correctly set up the segue; synthesized, added properties. But it seems to me the problem may be how I'm retrieving the data. Help would be greatly appreciated! Thank you in advance!
-(void)prepareForSegue:(UIStoryboardSegue *)segue user:(id<FBGraphUser>)user sender:(id)sender{
if([segue.identifier isEqualToString:#"loginInfo"]) {
NSString *name = user.name;
NSString *email = [user objectForKey:#"email"];
ViewController *vc = (ViewController *)[segue destinationViewController];
vc.userName = name;
vc.userEmail = email;
NSLog(#"user data is being prepared to segue");
}
}
You used -(void)prepareForSegue:(UIStoryboardSegue *)segue user:(id)user sender:(id)sender
There is no such method for segue unwinding in UIViewController class. Instead of that Use -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"loginInfo"]) {
NSString *name = user.name;
NSString *email = [user objectForKey:#"email"];
ViewController *vc = (ViewController *)[segue destinationViewController];
vc.userName = name;
vc.userEmail = email;
NSLog(#"user data %#, email %#",name,email);
}
}
To get the user info you need to implement facebook delegate.
- (void)meRequestResult:(id)result WithError:(NSError *)error
{
NSLog(#"result %#",result );
if ([result isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictionary;
if([result objectForKey:#"data"])
dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:#"data"] objectAtIndex:0];
else
dictionary = (NSDictionary *)result;
email = [dictionary valueForKey:#"email"];
fName = [dictionary valueForKey:#"first_name"];
lName = [dictionary valueForKey:#"last_name"];
}
}

I dont understand why i am passing nil through the segue way

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"CatagoryToSetDetail"]){
BYFSetsDetailViewController *controller = (BYFSetsDetailViewController *)segue.destinationViewController;
controller.workOut.catagory = catagory.text;
controller.workOut.excercise = excercize.text;
NSLog(#"passing the values %# \n and %# \n ",controller.workOut.catagory,controller.workOut.excercise);
}
for some reason controller.workOut.category is nil and i dont know how to fix it.
here is how i instantiated it in view did load
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.workOut = [[BYFWorkOut alloc]init];
NSLog(#"recieved values %# \n and %# \n ",_workOut.catagory,_workOut.excercise);
}
Thank you any help would be appreciated
prepareForSegue performed before viewDidLoad and yours workOut is nil when you tries assign category and excersize
Solution 1:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"CatagoryToSetDetail"]){
BYFSetsDetailViewController *controller = (BYFSetsDetailViewController *)segue.destinationViewController;
controller.workOut.catagory = catagory.text;
controller.workOut.excercise = excercize.text;
NSLog(#"passing the values %# \n and %# \n ",controller.workOut.catagory,controller.workOut.excercise);
}
in BYFSetsDetailViewController:
#implementation BYFSetsDetailViewController
#synthesyze workOut = _workOut;
- (id) initWithCoder:(NSCoder*) encoder
{
self = [super initWithCoder:encoder];
if (self)
{
_workOut = [[BYFWorkOut alloc] init];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"recieved values %# \n and %# \n ",_workOut.catagory,_workOut.excercise);
}
Solution 2:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"CatagoryToSetDetail"]){
BYFSetsDetailViewController *controller = (BYFSetsDetailViewController *)segue.destinationViewController;
controller.workOut = [[BYFWorkOut alloc]init];
controller.workOut.catagory = catagory.text;
controller.workOut.excercise = excercize.text;
NSLog(#"passing the values %# \n and %# \n ",controller.workOut.catagory,controller.workOut.excercise);
}
in BYFSetsDetailViewController:
#implementation BYFSetsDetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"recieved values %# \n and %# \n ",_workOut.catagory,_workOut.excercise);
}
Have you checked that category.text and exercise.text are not nil? - as those are the values you're passing to the destinationViewController in this method.
Also, where have you instantiated catagory.text and excercize.text ?
Edit
It looks like your custom object workOut has not been instantiated correctly. Do this in your init or viewDidLoad method of BYFSetsDetailViewController
Edit 2
Okay I got it work like this (Not sure why, maybe someone can explain more)
In your BYFSetsDetailViewController make a public property of NSString (I assume, workOut is an NSString?)
Then in your prepareForSegue method do this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"CatagoryToSetDetail"]){
BYFSetsDetailViewController *controller = (BYFSetsDetailViewController *)segue.destinationViewController;
controller.myString = catagory.text;
controller.myString2 = excercize.text;
NSLog(#"passing the values %# \n and %# \n ",controller.workOut.catagory,controller.workOut.excercise);
}
Declare your strings like this: #property (copy, nonatomic) NSString *myString
Then in your viewDidLoad method of BYFSetsDetailViewController
Do this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.workOut = [[BYFWorkOut alloc]init];
self.workOut.catagory = self.myString;
self.workOut.excercize = self.myString2;
NSLog(#"recieved values %# \n and %# \n ",_workOut.catagory,_workOut.excercise);
}
This should solve your issue.
Edit 3
From Cy-4AH's answer - do this in your prepareForSegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"CatagoryToSetDetail"]){
BYFSetsDetailViewController *controller = (BYFSetsDetailViewController *)segue.destinationViewController;
controller.workOut = [[BYFWorkOut alloc]init];
controller.workOut.catagory = catagory.text;
controller.workOut.excercise = excercize.text;
NSLog(#"passing the values %# \n and %# \n ",controller.workOut.catagory,controller.workOut.excercise);
Remember to import BYFWorkOut in this viewController at the top of the file.

Overlaying a transparent PNG on top of the current location blue dot

i'm just playing around with Apple's CurrentAddress sample code and I was trying to use the trueHeading property to determine the direction the user is facing. While that proved simple enough, I wanted to display a transparent PNG on top of the current location dot and I wanted to rotate it in order to simulate a compass.
Here's the very basic code I've currently got:
#implementation MapViewController
#synthesize mapView, reverseGeocoder, getAddressButton;
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation = YES;
}
- (IBAction)reverseGeocodeCurrentLocation
{
self.reverseGeocoder =
[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Cannot obtain address."
message:errorMessage
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
PlacemarkViewController *placemarkViewController =
[[PlacemarkViewController alloc] initWithNibName:#"PlacemarkViewController" bundle:nil];
placemarkViewController.placemark = placemark;
[self presentModalViewController:placemarkViewController animated:YES];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// we have received our current location, so enable the "Get Current Address" button
[getAddressButton setEnabled:YES];
NSString *north = [NSString stringWithFormat:#"%f", self.mapView.userLocation.heading.trueHeading];
NSLog(#"here: %#", north);
}
#end
How can I overlay the PNG to the exact position of the blue dot and keep it there (following the dot if the user moves, that is)?
The point is that you need to implement mapView:viewForAnnotation: delegate method and look inside it for annotation objects which are not yours. Take a look at the code snipped:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
NSString static *defaultID = #"defaultID";
NSString static *userLocationID = #"userLocationID";
if ([annotation isKindOfClass:[MyAnnotation class]]) {
// your code here
} else {
MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:userLocationID];
if (!annotationView) {
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationID] autorelease];
annotationView.image = [UIImage imageNamed:#"UserLocationIcon.png"];
}
return annotationView;
}
}

Resources