views:

456

answers:

2

I am new to iphone development.I am creating a map application. I have created tool bar with a button below the mapview.When i click the button it should display a alert view showing the current location and asking to update. on clicking OK in alert view should open my map with the current location and CANCEL to close the alert view.The button action is defined in the method

 -(IBAction) gosearch : (id) sender{
    NSLog(@"inside go search");

  }

What should i do to achieve my task.I have added core location framework.But i dont know how to proceed.I saw some inbuilt methods to be used from this link http://iappdevs.blog.co.in/2008/12/06/get-current-location-sample-example-iphone-programming/ but i am not able to implement it.Please guide me.Thanks.

+1  A: 

Where does your problem start - have you got a core location delegate that gets location updates? You need to start core location using these methods:

In applicationdidfinishingLauncing()

{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // Tells the location manager to send updates to this object
[locationManager startUpdatingLocation];

This will get core location to call you back as it gets updates on the location, starting with a rough location but further updates should get you a more accurate focus.

Chris Kimpton
The map is loaded intially with desired location,when clicking the button in the tool bar it should display the current location
Warrior
Does this work in simulator?(in general)
Warrior
Simulator does not simulate any location manager behavior.
Giao
@Giao ..>Thanks a lot,my code was working in device and not in simulator.
Warrior
Thanks it works fine...
Warrior
+2  A: 

the MapKit component MKMapView display the current position on its own, you don't have to do anything.

Actually, internally, it instantiates a CLLocationManager and starts updating location on it to get live position events. when it gets those positions, it displays them as a blue dot, with circles with various radius to indicate the accuracy, but this is done automatically.

To trigger the display of the current position on the MKMapView, just set the showsUserLocation to YES on your MKMapView instance and you'll get this this blue dot being displayed and updated in real time.

yonel