Fetch Location Name from Coordinates?

I have already Fetched the name of location through coordinates.

with this code

    reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];

here newLocation having my current location

and reverseGeocoder is the type of MKReverseGeocoder.

I also add the framework MapKit and add delegate MKReverseGeocoderDelegate.

and define this delegate in .m file

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{...}

when we start this delegate and get the location with (MKPlacemark*)placemark after that i show this with in an AlertView in above delegate method or any other user defined method like:

[[[[UIAlertView alloc] initWithTitle:@"Place" 
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
delegate:self 
cancelButtonTitle:@"Okay" 
otherButtonTitles:nil] autorelease] show];

Problem is that my alert view is appeared again and again in every second.

so please let me know how to stop the reverseGeocoder or how i can see this alert view just once.

thanx in advance.

Upvotes: 0

Views: 224

Answers (1)

Deepesh
Deepesh

Reputation: 8053

This problem is create , Because you have every time new location , this problem is remove from two way... 1) use distance condition between two location ...and when your distance is greater then a particular distance then you see alert view.....

2)if use want to see alert once time then use this code...

int count = 0;
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

.......
if(count == 0)
{
[[[[UIAlertView alloc] initWithTitle:@"Place" 
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
delegate:self 
cancelButtonTitle:@"Okay" 
otherButtonTitles:nil] autorelease] show];

count ++;

}
}

3)concept

NSString *previousloaction;/// use like global variable... NSString *currentloaction;/// use like global variable...

  -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
    {
    currentloaction=placemark;
    .......
   if(![previousloaction isEqucaltoString: currentloaction])
    {
    [[[[UIAlertView alloc] initWithTitle:@"Place" 
    message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease] 
    delegate:self 
    cancelButtonTitle:@"Okay" 
    otherButtonTitles:nil] autorelease] show];

   previousloaction =currentloaction;

    }
    }

Upvotes: 1

Related Questions