2012-02-09 186 views
0

我已经通过坐标获取了位置的名称。从坐标获取位置名称?

与此代码

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

这里newLocation有我的当前位置

和reverseGeocoder是MKReverseGeocoder的类型。

我还添加了框架MapKit并添加了委托MKReverseGeocoderDelegate。

,当我们开始这个委托,并获得与位置定义此委托在.m文件

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

(MKPlacemark *)后,该地标的我在上面的委托方法或任何其他的AlertView显示此用户定义的方法,如:

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

问题是,我的警报视图被一次又一次地出现在每一秒。

所以请让我知道如何停止reverseGeocoder或我如何才能看到这个警报视图一次。

thanx提前。

+0

是您展示用户当前的位置? – 2012-02-09 07:47:23

+0

是这段代码显示了我的当前位置,但是它每秒都会显示警报视图。 – 2012-02-09 07:50:20

+1

,因为您当前的位置更新,这就是为什么会引发此问题。请停止更新您的当前位置。或者使用一个bool变量。 \t \t [locationManager stopUpdatingLocation]; // locationManager是您的CLLocationManager – 2012-02-09 08:17:53

回答

1

这个问题是创造,因为你每一次新的位置,这个问题是双向删除... 1)使用两个位置之间的距离条件......而当你的距离是大于特定的距离,然后你看到警报视图.....

2)如果使用想看一次警报的时间,然后使用此代码...

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)概念

的NSString * previousloaction; // /使用像全局变量... 的NSString * currentloaction; ///使用像全局变量...

-(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; 

    } 
    } 
+0

等待我会检查出 – 2012-02-09 07:56:42

+0

如果你有任何问题,然后看到这个网址(我有使用此conecpt)http://stackoverflow.com/questions/1382900/how-to-retrive-users-current-city-name – Deepesh 2012-02-09 08:06:55

+0

我已经看到这个链接,他们在NSSTring *城市有价值;但他们没有在任何地方显示。 – 2012-02-09 08:48:28