2012-02-03 67 views
3

我正在iphone中做一個基於地圖的應用程序。我從地址簿中獲取我的數據(地址)。當提供正確的地址時,地點被正確固定。但是當輸入錯誤的地址(如XYZ而不是像紐約這樣正確的城市名稱)時,這些引腳會落入地圖的(0,0)座標或加拿大的某個隨機位置。我該如何處理這種情況。在mapview中處理錯誤的地址

回答

3

你可以檢查一個無效的座標使用kCLLocationCoordinate2DInvalid不變,是這樣的:

if ((coord.latitude == kCLLocationCoordinate2DInvalid.latitude) || (coord.longitude == kCLLocationCoordinate2DInvalid.longitude)) 
{ 
    NSLog(@"Invalid coordinate"); 
} 
else 
{ 
    // Valid coordinate, add it to the map 
}