Hello!
I have a problem what I suppose is rather trivial... I have coded an app using the mapkit and have done the development on my Mac using the simulator which has no GPS. Therefore did I hard code the coordinates to simulate a user position. Today as I tried my app on my iPhone for the first time I thought I only had to change my code a bit in order to read the coordinates from the GPS and to get the information about the users position. But it did not work that easy. Does anyone have an idea how to solve this? I need the user longitude and latitude to calculate the distance to another position and I thought I could do something like this...?
I need the coordinates but cant figure out how to get them...any ideas? Thanks in advance!
I have a problem what I suppose is rather trivial... I have coded an app using the mapkit and have done the development on my Mac using the simulator which has no GPS. Therefore did I hard code the coordinates to simulate a user position. Today as I tried my app on my iPhone for the first time I thought I only had to change my code a bit in order to read the coordinates from the GPS and to get the information about the users position. But it did not work that easy. Does anyone have an idea how to solve this? I need the user longitude and latitude to calculate the distance to another position and I thought I could do something like this...?
Code:
CLLocationManager *clm = [[CLLocationManager alloc]init];
[clm.delegate self]; [clm startUpdatingLocation];
userLocationFromGPS = clm.location.coordinate;
//the userLocationFromGPS is a CLLocationCoordinate2D userLocationFromGPS object
user = [[Annotations alloc]initWithCoordinate:userLocationFromGPS];
[user setTheTitle:@"You are here!"];
userLocationPlain =
[[CLLocation alloc]initWithLatitude:userLocationFromGPS.latitude longitude:userLocationFromGPS.longitude];
I need the coordinates but cant figure out how to get them...any ideas? Thanks in advance!