Obtain user location from a MKMapView - iphone

Is it possible to use the MKMapView's own location manager to return the users current location to pass into a webservice?
I have mapView.showsUserLocation=YES; and this does return a valid blue dot at my location, but in the simulator, its Cupertino - which is fine, but when i look at
mapView.userLocation.coordinate.latitude, its equal to 180, whereas a CLLocationManager returns the correct one, 37.3317.
I want to avoid having multiple location managers for my three tabs, so using the mapViews own would be helpful.
Thanks.

You can get the user location from the MKMapView. You are just missing a property in your retrieval of it. It should be:
mapView.userLocation.location.coordinate.latitude;
userLocation only stores a CLLocation location attribute and a BOOL updating attribute. You must go to the location attribute to get coordinates.
-Drew
EDIT: The MKMapView's userLocation does not update until the map has finished loading, and checking too early will return zeros. To avoid this, I suggest using the MKMapViewDelegate method
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation.

So, to use a unique CLLocateManager, you can create a class to be the delegate for all you maps., so, instead of doing:
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
Do something like:
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = mySharedDelegate;
Where mySharedDelegate is your class with all the CLLocationManager delegate methods.
You can only get a valid coordinate for the userLocation, after the first calling of - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
When this method is called it is because the GPS has found the new location and so the blue dot will be moved to there and the userLocation will have the new coordinate.
Use the following method on your CLLocationManager delegate to log the current location when it is found:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"---------- locationManager didUpdateToLocation");
location=newLocation.coordinate;
NSLog(#"Location after calibration, user location (%f, %f)", _mapView.userLocation.coordinate.latitude, _mapView.userLocation.coordinate.longitude);
}
Have you got the idea?
Cheers,
VFN

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(#"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MyMapannotation class]])
{
MyMapannotation *annotation12=(MyMapannotation *)annotation;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] ;
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
pinView.tag=annotation12.tag;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
rightButton.tag=annotation12.tag;
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"artpin"]];
pinView.image = profileIconView.image;
return pinView;
}
else
return nil;
}
-(IBAction)showDetails:(id)sender
{
UIButton *btn=(UIButton *)sender;
}
-(void)Load_mapview
{
for (int i=0; i<[arr_nearby count]; i++)
{
NSNumber *latitude = [[[[arr_nearby objectAtIndex:i] valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lat"];
NSNumber *longitude = [[[[arr_nearby objectAtIndex:i] valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lng"];
NSString *title = [[arr_nearby objectAtIndex:i] valueForKey:#"name"];
//Create coordinates from the latitude and longitude values
CLLocationCoordinate2D coord;
coord.latitude = latitude.doubleValue;
coord.longitude = longitude.doubleValue;
MyMapannotation *annotation = [[MyMapannotation alloc] initWithTitle:title AndCoordinate:coord andtag:i];
[_map_nearby addAnnotation:annotation];
// [annotations addObject:annotation];
}
[self zoomToLocation];
}
-(void)zoomToLocation
{
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = [[[[[arr_nearby objectAtIndex:0] valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lat"] floatValue];
zoomLocation.longitude= [[[[[arr_nearby objectAtIndex:0] valueForKey:#"geometry"] valueForKey:#"location"] valueForKey:#"lng"] floatValue];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 7.5*5,7.5*5);
[_map_nearby setRegion:viewRegion animated:YES];
[_map_nearby regionThatFits:viewRegion];
}
//
// MyMapannotation.h
// IOS_Googgle
//
// Created by Vivek Chauhan on 27/06/16.
// Copyright (c) 2016 anand. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MyMapannotation : NSObject <MKAnnotation>
#property (nonatomic,copy) NSString *title;
#property (nonatomic,assign) int tag;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
-(id) initWithTitle:(NSString *) title AndCoordinate:(CLLocationCoordinate2D)coordinate andtag:(int)tagofbutton;
#end
//
// MyMapannotation.m
// IOS_Googgle
//
// Created by Vivek Chauhan on 27/06/16.
// Copyright (c) 2016 anand. All rights reserved.
//
#import "MyMapannotation.h"
#implementation MyMapannotation
#synthesize coordinate=_coordinate;
#synthesize title=_title;
#synthesize tag=_tag;
-(id) initWithTitle:(NSString *) title AndCoordinate:(CLLocationCoordinate2D)coordinate andtag:(int)tagofbutton
{
self = [super init];
_title = title;
_coordinate = coordinate;
_tag=tagofbutton;
return self;
}
#end

Related

MapView only shows correct location after 2nd load

Im struggling with a mapview on my app. When loading the screen with the mapview on, the map just opens to the default location for mapviews. However, when I return to the previous scren and then launch the map for a 2nd time, the correct location is displayed.
Obviously, this isn't ideal.
Any suggestions please?
My code is:
CLLocation *mapLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
[[self map] setCenterCoordinate:[mapLocation coordinate]];
[[self map] setRegion: MKCoordinateRegionMakeWithDistance([mapLocation coordinate], 1000, 1000)];
MapAnnotation *annotation = [[MapAnnotation alloc] init];
[annotation setCoordinate:[mapLocation coordinate]];
[[self map] addAnnotation:annotation];
Thank you!
I set the current location like this:
Location.h:
#interface WhereamiViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate, UITextFieldDelegate> {
CLLocationManager *locationManager;
MKMapView *worldView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextField *locationTextField;
}
- (void)findLocation;
- (void)foundLocation:(CLLocation *)loc;
- (IBAction)setMapTyp:(id)sender;
#property MKMapType mapType;
#property (nonatomic, retain) IBOutlet MKMapView *worldView;
#property (nonatomic, readonly) NSDate *currentDate;
#end
Location.m:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(#"%#", newLocation);
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
if (t < -180) {
return;
}
[self foundLocation:newLocation];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
NSLog(#"Could not find location: %#", error);
}
- (void)findLocation {
[locationManager startUpdatingLocation];
[activityIndicator startAnimating];
[locationTextField setHidden:YES];
}
- (void)foundLocation:(CLLocation *)loc {
CLLocationCoordinate2D coord = [loc coordinate];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:#"HH:mm, dd. MMM. yyyy "];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [format stringFromDate:now];
MyOwnMapPoint *mp = [[MyOwnMapPoint alloc] initWithCoordinate:coord
title:[locationTextField text]
subtitle:dateString];
NSLog(#"Die Uhrzeit ist: %#", dateString);
[worldView addAnnotation:mp];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
[worldView setRegion:region animated:YES];
//Reset the UI
[locationTextField setText:#""];
[activityIndicator stopAnimating];
[locationTextField setHidden:NO];
[locationManager stopUpdatingLocation];
}
Hope its giving you an idea!

How to call MKAnnotation Method in another Method using Objective C

-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
}
MKAnnotationView method is used to display icon in map. How to call MKAnnotationView method in -didUpdateToLocation method using objective-c?
i'm not sure if this is what you want but :
here's the class that i've written for annotations :
.h file :
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MyLocation : NSObject <MKAnnotation> {
NSString *_name;
NSString *_address;
CLLocationCoordinate2D _coordinate;
}
#property (copy) NSString *name;
#property (copy) NSString *address;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate;
#end
and the .m file :
#import "MyLocation.h"
#implementation MyLocation
#synthesize name = _name;
#synthesize address = _address;
#synthesize coordinate = _coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate {
if ((self = [super init])) {
_name = [name copy];
_address = [address copy];
_coordinate = coordinate;
}
return self;
}
- (NSString *)title {
if ([_name isKindOfClass:[NSNull class]])
return #"Unknown charge";
else
return _name;
}
- (NSString *)subtitle {
return _address;
}
#end
and in the view controller i am calling location manager like :
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 10.0; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
and then in the location manager's delegate method i am setting my map like this:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[locationManager stopUpdatingLocation];
//CLLocationCoordinate2D newCoord = { newLocation.coordinate.latitude, newLocation.coordinate.longitude };
CLLocationCoordinate2D centerPoint = { newLocation.coordinate.latitude, newLocation.coordinate.longitude };
MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(0.01, 0.01);
MKCoordinateRegion coordinateRegion = MKCoordinateRegionMake(centerPoint, coordinateSpan);
["your-map-name" setRegion:coordinateRegion];
["your-map-name" regionThatFits:coordinateRegion];
CLLocationCoordinate2D cordPoint = { latitude_value, longitude_value };
MyLocation *annotation = [[MyLocation alloc] initWithName:#"title of the pin" address:#"some sub string" coordinate:cordPoint] ;
["your-map-name" addAnnotation:annotation]; }
this is how i solved my annotation and map problem ..
i hope this helps..

unable to display custom Annotations on the map in iPhone

I am trying to add annotations on my mapview but I am not able to add them. Can someone suggest me where I am doing wrong? Code: Code to add the map:
mapview = [[MKMapView alloc] initWithFrame:CGRectMake(10, 175, 300, 268)];
mapview.delegate = self;
mapview.userInteractionEnabled = TRUE;
[mapview setZoomEnabled:TRUE];
[mapview setScrollEnabled:TRUE];
mapview.showsUserLocation = TRUE;
[self.view addSubview:mapview];
//adding annotations in another method:
for (id annotation in mapview.annotations) {
[mapview removeAnnotation:annotation];
}
for(int i =0;i<arrEventList.count;i++){
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = [[NSString stringWithFormat:#"%#",[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:#"lat"]] floatValue];
theCoordinate.longitude = [[NSString stringWithFormat:#"%#",[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:#"lng"]] floatValue];
MyLocation *annotation = [[[MyLocation alloc] initWithName:[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:#"event"] address:[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:#"place"] coordinate:theCoordinate] autorelease];
[mapview addAnnotation:annotation];
//[annotations addObject:myAnno.annotation];
}
// delegate method:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
static NSString *identifier = #"MyLocation";
if ([annotation isKindOfClass:[MyLocation class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image=[UIImage imageNamed:#"annotation.png"];//here we use a nice image instead of the default pins
return annotationView;
}
return nil;
}
Above delegate method is only called for self location but it is not called for other annotations that I want to add.
Can someone point me to my mistakes
#interface MyLocation : NSObject <MKAnnotation> {
NSString *_name;
NSString *_address;
CLLocationCoordinate2D _coordinate;
}
#property (copy) NSString *name;
#property (copy) NSString *address;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate;
#end
//Mylocation class:
#implementation MyLocation
#synthesize name = _name;
#synthesize address = _address;
#synthesize coordinate = _coordinate;
- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate {
if ((self = [super init])) {
_name = [name copy];
_address = [address copy];
_coordinate = coordinate;
}
return self;
}
- (NSString *)title {
if ([_name isKindOfClass:[NSNull class]])
return #"Unknown charge";
else
return _name;
}
- (NSString *)subtitle {
return _address;
}
I found the problem. My code is correct. The values of latittude and longitudes were some how interchanged. My mistake but I have corrected it now

How to get user's location in a later screen for the MapKit?

I am building a navigation-based app for the iPhone, where I calculate the user's geolocation in the RootViewController (this is the code for my RootViewController.h) class:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "SecondViewController.h"
#import <sqlite3.h>
#interface RootViewController : UITableViewController <CLLocationManagerDelegate>{
SecondViewController *secondViewController;
NSUInteger numUpdates;
CLLocationManager *lm;
CLLocation *firstLocation;
CLLocation *secondLocation;
}
#property (nonatomic, retain) SecondViewController *secondViewController;
#property (nonatomic, retain) NSMutableArray *restaurants;
#property (nonatomic, retain) NSArray *sortedRestaurants;
here is the code for my RootViewController.m class:
- (void) locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D location;
NSString *lat = [[NSString alloc] initWithFormat:#"%g", newLocation.coordinate.latitude];
double lat1 = newLocation.coordinate.latitude;
location.latitude = newLocation.coordinate.latitude; //setting the latitude property of the location variable
NSString *lng = [[NSString alloc] initWithFormat:#"%g", newLocation.coordinate.longitude];
double lon1 = newLocation.coordinate.longitude;
location.longitude = newLocation.coordinate.longitude; //setting the longitude property of the location variable
MapViewController *mController = [[MapViewController alloc] initWithNibName:#"MapViewController" bundle:[NSBundle mainBundle]];
self.mapViewController = mController;
[mController release];
self.mapViewController.userCoord = [[[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude] autorelease];
//in the above line I get the error, "incompatible type for argument 1 of 'setUserCoord' "
[lm stopUpdatingLocation];
Because I am calculating the user's geolocation in the RootViewController class, I would like to re-use these value when I use the MapKit later on in the application in the MapViewController.m class:
- (void)viewDidLoad {
[super viewDidLoad];
MKCoordinateRegion region;
MKCoordinateSpan span;
region.center = userCoord;
/* userCoord is declared as an object of type CLLocationCoordinate2D
in MapViewController.h, and is declared as a property, and then
synthesized in the .m class. Even though I am trying to center
the map on the user's coordinates, the map is neither centering,
nor zooming to my settings. */
span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;
region.span = span;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation = YES;
[mapView setRegion:region animated:YES];
RestaurantAnnotation *rAnnotation = [[RestaurantAnnotation alloc] init];
rAnnotation.title = restaurantObj.name;
rAnnotation.subTitle = restaurantObj.address;
CLLocationCoordinate2D newCoord = {restaurantObj.latitude, restaurantObj.longitude};
rAnnotation.coordinate = newCoord;
[mapView addAnnotation:rAnnotation];
}
I would like the map to be centered on the user's location, and choose appropriate span values as well.
There are a lot of ways to do this, the way I've done it is to store the location in NSUserDefaults and access that value later when I'm presenting my map. The benefit of doing it this way is that the user's location persists between runs, so if the next time they open the app they're having trouble getting a GPS signal, you still have a location to display.
This code may not be 100%, i'm writing it from memory:
#define latKey #"latKey"
#define lonKey #"lonKey"
#define locationKey #"locationKey"
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSNumber *lat = [NSNumber numberWithDouble:newLocation.coordinate.latitude];
NSNumber *lon = [NSNumber numberWithDouble:newLocation.coordinate.longitude];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:lat, latKey, lon, lonKey, nil];
[[NSUserDefaults standardUserDefaults] addObjectForKey:locationKey];
}
- (void)viewDidLoad {
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] dictForKey:locationKey];
CLLocation *location = [[CLLocation alloc] initWithLatitude:[[dict objectForKey:lat] doubleValue] longitude:[[dict objectForKey:lon] doubleValue]];
}

I am not able to give an MKAnnotation an image!

Hey guys! I am having some trouble with giving an MKAnnotationView an image instead of a pin view. In other words, I am having trouble displaying a target image (target.png) instead of the normal pin view. Here is my code---
// .h file
#import //Here it says to import mapkit & UIKit. The code blockquote doesn't let me
#import //show you that
#interface AddressAnnotation : NSObject {
CLLocationCoordinate2D coordinate;
NSString *mTitle;
NSString *mSubTitle;
}
#end
#interface ChosenLocationMap : UIViewController {
IBOutlet MKMapView *mapView;
AddressAnnotation *addAnnotation;
}
-(CLLocationCoordinate2D) addressLocation;
// .m file
#implementation AddressAnnotation
#synthesize coordinate;
- (NSString *)subtitle{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *stitle = [prefs objectForKey:#"addressKey"];
return #"%#",stitle;
}
- (NSString *)title{
return #"TARGET";
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(#"%f,%f",c.latitude,c.longitude);
return self;
}
#end
#implementation ChosenLocationMap
#synthesize destinationLabel, startbutton, accelloop, aimview, bombblowupview, bombleftview1, bombleftview2, bombleftview3, firebutton;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)viewDidLoad {
mapView.mapType = MKMapTypeSatellite;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location = [self addressLocation];
region.span=span;
region.center=location;
if(addAnnotation != nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];
[super viewDidLoad];
}
-(CLLocationCoordinate2D) addressLocation {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *destinationstring = [prefs objectForKey:#"addressKey"];
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[destinationstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:#","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:#"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
- (MKAnnotationView *)map:(MKMapView *)map viewForAnnotation:(id )annotation{
MKAnnotationView *annView;
annView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:annotation.title];
if(annView == nil)
annView = [[[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:annotation.title] autorelease];
else
annView.annotation = annotation;
[annView setImage:[UIImage imageNamed:#"target.png"]];
annView.canShowCallout = TRUE;
return annView;
}
Please note that I only included the code that actually involves the mapview. Thanks in advance!
EDIT: I Changed the code in my Xcode document for the changes in answer 1. I am too lazy to transfer everything to the code block above, and still, the picture still doesn't work.
SHOOP DA EDIT: Thank you for replying! My solution was that I forgot to say mapView.delegate = self. Bye!
Wow so much wrong with this code :-)
First you are missing a #property declaration in your AddressAnnotation
#property (nonatomic,assign) CLLocationCoordinate2D coordinate;
In the subtitle method you do this:
return #"%#",stitle;
But this is Objective-C and not Python, so you might want to change this to:
return stitle;
Then your initWithCoordinate is completely wrong. You do not initialize super. This is better:
-(id) initWithCoordinate: (CLLocationCoordinate2D) c
{
if ((self = [super init]) != nil) {
coordinate=c;
NSLog(#"%f,%f",c.latitude,c.longitude);
}
return self;
}
Try fixing that stuff first to see if it helps :-)
I'm new to Objective C but I think the prototype for your delegate function should be :
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id )annotation{
MKAnnotationView *annView;
The delegate name is mapView:viewForAnnotation:, not map:viewForAnnotation:
Also you AddressAnnotation doesn't implement the MKAnnotation protocol