我尝试了两种不同的方法来尝试仅从Address类获取城市名称和州名缩写,没有运气.第一种是使用邮政编码返回状态"CA 92055",第二次尝试返回完整的州名.有什么快速的方法吗?
国家最终返回"CA 92055"的第一次尝试(Zip后面的缩写)
Geocoder geoCoder = new Geocoder(getActivity(), Locale.getDefault());
List<Address> addresses;
try {
addresses = geoCoder.getFromLocation(mLatitude, mLongitude, 10);
int i=1;
for(Address addObj:addresses)
{
// Looping once
if(i==1)
{
String add_line1_extract;
add_line1_extract=addObj.getAddressLine(1);
String string = add_line1_extract;
String[] parts = string.split(",");
//Setting city
mCity = parts[0];
//setting state
mState = parts[1];
// Final Output
String cityAndState = mCity + ", " + mState;
i++;
}
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试,现在越来越没有拉链......但......(返回完整的州名):
Geocoder geoCoder …Run Code Online (Sandbox Code Playgroud) 我试图将我的UISearchBar直接置于我的UINavigationBar下,但我遇到的问题是它根本没有出现.我正在使用iOS8的新searchController.
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.salesTableView.tableHeaderView = self.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)
目前我正在使用正确添加到我的UITableView标头的那个,但问题是它滚动表不是我想要的表.我想把它放在我的tableview之上,所以它反而尝试了但现在似乎已经消失了,除非我没有使用正确的值?
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(0, 0, self.searchController.searchBar.frame.size.width, 44.0);
// self.salesTableView.tableHeaderView = self.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)