選擇中國(guó)城市(省/市)
源代碼:https://github.com/thanwork/citychoose
主要功能
- 搜索列表中展示的中國(guó)所有城市
- 基于定位的城市選擇
- 熱點(diǎn)城市展示(隨便寫了9個(gè)城市。。。)

IMG_0052.png
代碼實(shí)現(xiàn)
寫代碼之前
由于定位使用的是高德定位API,需要先在高德開發(fā)者網(wǎng)站上申請(qǐng)apikey;
所有view使用代碼實(shí)現(xiàn),并未采用storyboard創(chuàng)建,而是使用snapkit
代碼實(shí)現(xiàn)
一個(gè)tableview+2個(gè)cell
-
tableview的實(shí)現(xiàn)
class CityChooseView : UIViewController,UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,CityCellDelegate
主要就是實(shí)現(xiàn)一個(gè)tableview,同時(shí)在這個(gè)view中實(shí)現(xiàn)定位獲取的城市信息
func fetchLocation() {
aMapLocationManager.requestLocationWithReGeocode(true) { (alocation, regeocode, error) -> Void in
if(regeocode != nil){
self.locationcity = regeocode.city
self.locationprovince = regeocode.province
self.tableView.reloadData()
}
}
}
- 實(shí)現(xiàn)兩個(gè)tableviewcell,一個(gè)展示定位城市和熱點(diǎn)城市,另一個(gè)列表方式展示所有的中國(guó)城市
使用方法
-
配置高德apikey
AMapLocationServices.sharedServices().apiKey = "" 集成snapkit,最好使用cocoapod
實(shí)現(xiàn)接口CityChooseViewDelegate
獲取國(guó)家(中國(guó)),省,市