Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nejdetkadir/turkish_cities
A comprehensive library for managing Turkish cities and their administrative divisions (towns, districts, quarters) in Go
https://github.com/nejdetkadir/turkish_cities
go golang golang-library golang-package turkey turkey-cities turkey-districts turkey-map turkey-towns turkish turkish-dataset
Last synced: 15 days ago
JSON representation
A comprehensive library for managing Turkish cities and their administrative divisions (towns, districts, quarters) in Go
- Host: GitHub
- URL: https://github.com/nejdetkadir/turkish_cities
- Owner: nejdetkadir
- License: mit
- Created: 2024-07-06T14:16:35.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-06T14:21:26.000Z (4 months ago)
- Last Synced: 2024-10-16T02:01:29.405Z (30 days ago)
- Topics: go, golang, golang-library, golang-package, turkey, turkey-cities, turkey-districts, turkey-map, turkey-towns, turkish, turkish-dataset
- Language: Go
- Homepage:
- Size: 1.09 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![Build and test](https://github.com/nejdetkadir/turkish_cities/actions/workflows/main.yml/badge.svg?branch=main)
![Go Version](https://img.shields.io/badge/go_version-_1.22.2-007d9c.svg)![cover](docs/cover.png)
# TurkishCities
TurkishCities is a comprehensive library for managing Turkish cities and their administrative divisions (towns, districts, quarters) in Go. It provides an easy way to load, query, and interact with this hierarchical data structure.
## Features
- Latest data for Turkish cities, towns, districts, and quarters
- Query cities, towns, districts, and quarters by IDs
- Access country-level information## Installation
To install TurkishCities, use go get:```bash
go get github.com/nejdetkadir/turkish_cities
```## Usage
### Loading Data
Load city data from a JSON file:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()firstCity := tc.GetCities()[0]
firstTown := firstCity.GetTowns()[0]
firstDistrict := firstTown.GetDistricts()[0]
firstQuarter := firstDistrict.GetQuarters()[0]fmt.Println("total cities count: ", len(tc.GetCities()))
// total cities count: 81fmt.Println("city id: ", firstCity.ID)
// city id: 69fmt.Println("city name: ", firstCity.Name)
// city name: Bayburtfmt.Println("city latitude/longitude: ", firstCity.Location.Latitude, firstCity.Location.Longitude)
// city latitude/longitude: 0x140000a7828 0x140000a7830fmt.Println("towns of city count: ", len(firstCity.GetTowns()))
// towns of city count: 3fmt.Println("town id: ", firstTown.ID)
// town id: 884fmt.Println("town name: ", firstTown.Name)
// town name: Aydıntepefmt.Println("town latitude/longitude: ", firstTown.Location.Latitude, firstTown.Location.Longitude)
// town latitude/longitude: 0x140000a6928 0x140000a6930fmt.Println("districts of town count: ", len(firstTown.GetDistricts()))
// districts of town count: 2fmt.Println("district id: ", firstDistrict.ID)
// district id: 4166fmt.Println("district name: ", firstDistrict.Name)
// district name: Aydıntepefmt.Println("district latitude/longitude: ", firstDistrict.Location.Latitude, firstDistrict.Location.Longitude)
// district latitude/longitude:fmt.Println("quarters of district count: ", len(firstDistrict.GetQuarters()))
// quarters of district count: 5fmt.Println("quarter id: ", firstQuarter.ID)
// quarter id: 47917fmt.Println("quarter name: ", firstQuarter.Name)
// quarter name: Ahmet Yesevi Mah.fmt.Println("quarter latitude/longitude: ", firstQuarter.Location.Latitude, firstQuarter.Location.Longitude)
// quarter latitude/longitude: 0x1400000e720 0x1400000e728
}
```### Country Information
Access country-level information:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()country := tc.GetCountry()
fmt.Println("country name:", country.Name)
// country name: Türkiye
fmt.Println("country a2c:", country.Alpha2Code)
// country a2c: TR
fmt.Println("country a3c:", country.Alpha3Code)
// country a3c: TUR
fmt.Println("country abbreviation:", country.Abbreviation)
// country abbreviation: TR
fmt.Println("country phone code:", country.PhoneCode)
// country phone code: +90
}
```### Querying Cities
Query cities by ID:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()
foundCity := tc.GetCityByID(55)
if foundCity != nil {
fmt.Println("city found: ", foundCity.Name)
// city found: Samsun
} else {
fmt.Println("city not found")
}
}
```### Querying Towns
Query towns by ID:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()cityId := 55
townId := 737foundTown := tc.GetTownByID(cityId, townId)
if foundTown != nil {
fmt.Println("town found: ", foundTown.Name)
// town found: Bafra
} else {
fmt.Println("town not found")
}
}
```### Querying Districts
Query districts by ID:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()cityId := 55
townId := 737
districtId := 5387foundDistrict := tc.GetDistrictByID(cityId, townId, districtId)
if foundDistrict != nil {
fmt.Println("district found: ", foundDistrict.Name)
// district found: Merkez
} else {
fmt.Println("district not found")
}
}
```### Querying Quarters
Query quarters by ID:```go
package mainimport (
"fmt"
"github.com/nejdetkadir/turkish_cities"
)func main() {
tc := turkish_cities.Load()cityId := 55
townId := 737
districtId := 5387
quarterId := 37805foundQuarter := tc.GetQuarterByID(cityId, townId, districtId, quarterId)
if foundQuarter != nil {
fmt.Println("quarter found: ", foundQuarter.Name)
// quarter found: İshaklı Mh.
} else {
fmt.Println("quarter not found")
}
}
```## Testing
To run the tests, use go test:```bash
$ go test ./...
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/nejdetkadir/turkish_cities. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nejdetkadir/turkish_cities/blob/main/CODE_OF_CONDUCT.md).## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.