开发者

How to find the current location of iphone and update it

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜