2012-02-09 125 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