Reputation: 2348
I need to display my current position in Map Kit, how can I do this ?
self.map.showsUserLocation = TRUE;
is not showing my location instead a point somewhere else in the map? I need to find the location from where I am accessing the application. Please help me in this.. Thanks in advance
Upvotes: 1
Views: 1027
Reputation: 2348
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",degrees, minutes, seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
longLabel.text = longt;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = newLocation.coordinate.latitude;
region.center.longitude = newLocation.coordinate.longitude;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
}
Upvotes: 0
Reputation: 28750
You need to use location manager for getting your current location. And then get the lat long value and create a annonation and display on map. If you use map.showsUserLocation = TRUE; it will show your current location in actual device.
Note - In simulator map kit shows apple's head quarter location somewhere in Cupertino - I don't remember exactly.
Upvotes: 1