tags:

views:

22

answers:

2

I want to read my current location Using Map view in my iphone application.

My current location may be changed depends upon Timing.

Now i will be one location, after one hour i will be travel some Kilometers..

But my aim is, when ever i will be there, that current location, I will be want to read.

If there is any way to possible to read like this.

If anybody known Please help me.

Thanks.

+1  A: 

Take a look at the Core location manager. http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/

It's fairly straight forward:

  • Create a location manager and register a delegate.
  • Start the location manager.
  • When the location manager detects a change in location, it'll notify your delegate via locationManager:didUpdateToLocation:fromLocation:

The Map View is a presentational component - if you want to get control over location awareness use the location manager.

dannywartnaby
+1  A: 

If you have a MKMapView object called mapView, you'd do:

mapView.showsUserLocation = YES;

That'll turn on MKMapView's built in location services. You don't need to deal with CLLocation Manager necessarily, because MKMapView will handle the work of locating the device for you.

Now, receiving the updates that MKMapView produces is a touch trickier if you've never worked with delegates before.

In your .h, you want to adopt the <MKMapViewDelegate> protocol.

Then, right next the above line, say:

mapView.delegate = self;

Then, implement the following method:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    // inside here, userLocation is the MKUserLocation object representing your
    // current position. 

    CLLocation *whereIAm = userLocation.location;
    NSLog(@"I'm at %@", whereIAm.description);

    float latitude = whereAmI.coordinate.latitude;
    float longitude = whereAmI.coordinate.longitude;

    // etc.

}

That method will get called every time MKMapView updates its location, probably every few seconds at least.

Dan Ray
Thanks for your reply. It is very useful to me. it is working good.
Velmurugan