2013-11-22 24 views
1

在我的應用程序中,我有一個地圖視圖和兩個文本框。
文本框包含註釋的座標。
如果我在這些文本框中輸入座標並按下提交按鈕,則會繪製相應座標的註釋。
但是,如果我沒有在文本框中輸入任何值並按提交按鈕,則在舊金山繪製了註釋。在地圖上顯示註釋時出錯

- (IBAction)submitButton:(id)sender 
{ 
myCoordinate.latitude=[latitude_value.text floatValue]; 
myCoordinate.longitude=[longitude_value.text floatValue]; 
CLLocationDistance distance=1000; 
MKCoordinateRegion newRegion=MKCoordinateRegionMakeWithDistance(myCoordinate,   distance,distance); 
[self.mapView setRegion:region animated:YES]; 
MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init]; 
annotation.coordinate = myCoordinate; 
[self.mapView addAnnotation:annotation]; 

}

的2個文本框是latitude_value和longitude_value。
請幫忙....!

+0

如果文本框是真的是一片空白,座標將被設置爲0,0這是在大西洋(未舊金山)。 NSLog文本框和myCoordinate的值(設置其經度和緯度後)。 – Anna

+0

好吧,我用下面的代碼,我寫了,任何方式謝謝你的迴應。 – chandru

+0

你也可以檢查這一點,http://stackoverflow.com/questions/20143169/error-in-drawing-polyline-in-ios?noredirect = 1#comment30024334_20143169 – chandru

回答

1

由於文本爲空,可能會將其轉換爲0.000,0.000左右,更好的方法是檢查[latitude_value.text isEqualToString:@""],如果不是則繼續執行您的任務。讓我知道這是否有幫助。

我猜如果這失敗了,你可以從地圖中刪除所有註釋。

+0

謝謝你的朋友,因爲你只,我得到了一個關於它的想法。 – chandru

+0

你也可以檢查這個,http://stackoverflow.com/questions/20143169/error-in-drawing-polyline-in-ios?noredirect = 1#comment30024334_20143169 – chandru

+0

我回答了你的問題。讓我知道是有幫助的。 –

0

我明白了,通過下面的代碼。

if (latitude_value.text==NULL && longitude_value.text==NULL) { 
    NSLog(@"nothing to display"); 
} 

感謝ü@iRavi