Documentation
¶
Index ¶
- Constants
- Variables
- func DegToRad(deg float64) float64
- func LONGITUDE_PER_METRE(l float64) float64
- func MapAppend[R Regionable](dataMap *map[string][]R, k string, data R)
- func RadToDeg(rad float64) float64
- func RequestThenUnmarshall[R Unmarshallable](url string, data *R) error
- type BatchData
- type BatchPlace
- type Category
- type City
- type CityPlace
- type CityRequest
- type CoreInfo
- type DataCityReq
- type DataDistrictReq
- type DataVillageReq
- type DirectionH
- type DirectionV
- type District
- type DistrictRequest
- type Location
- type Place
- type Regionable
- type Unmarshallable
- type Village
- type VillageRequest
- type WebQuery
Constants ¶
const ( // in meter RADIUS_DISTRIBUTION_CITY float64 = 5000 RADIUS_DISTRIBUTION_DISTRICT float64 = 3000 RADIUS_DISTRIBUTION_VILLAGE float64 = 1500 )
* Assumptions about distribute random places: * - Due unknown border locations, assume below constants * are a safe radius for distributing random places which * those places are still belong to such region we referred to, * Eventhough in real life, the provided location isn't centralized * against the shape as overall and has various distance to its border * Also some places discovered (not did much reasearches) have really short * distance to its border from its provided location (about < 1km)
const ( VILLAGE_URL string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_kode_wilayah_dan_nama_wilayah_desa_kelurahan?limit=5957" DISTRICT_URL string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_16357_kode_wilayah_dan_nama_wilayah_kecamatan?limit=627" CITY_URL string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_kode_wilayah_dan_nama_wilayah_kota_kabupaten?limit=27" )
const (
LATITUDE_PER_METRE = 1 / (111.32 * 1000)
)
Assuming that the Earth is a sphere with a circumference of 40075 km. So, Length in meters of 1° of latitude = always 111.32 km Length in meters of 1° of longitude = 40075 km * cos( latitude ) / 360
Variables ¶
var MapCategories = map[string][]Category{
"city": {
{ID: 1, Name: "Kantor Pemerintah", Count: 1},
{ID: 2, Name: "Rumah Sakit", Count: 3},
{ID: 3, Name: "SMA", Count: 20},
},
"district": {
{ID: 4, Name: "Kantor Pemerintah Kecamatan", Count: 1},
{ID: 5, Name: "Puskesmas", Count: 5},
{ID: 6, Name: "SMP", Count: 3},
},
"village": {
{ID: 7, Name: "Kantor Pemerintah", Count: 1},
{ID: 8, Name: "Tempat Ibadah", Count: 20},
{ID: 9, Name: "SD", Count: 5},
},
}
Predefined categories, mapped by their region level ID 1-3 city level ID 4-6 district level ID 7-9 village level
Functions ¶
func LONGITUDE_PER_METRE ¶
func MapAppend ¶
func MapAppend[R Regionable](dataMap *map[string][]R, k string, data R)
Using generic, check if key exists of a region structs, append to value which is a slice If doesn't extist, initialize the new one
func RequestThenUnmarshall ¶
func RequestThenUnmarshall[R Unmarshallable](url string, data *R) error
Using generic, request to the given URL and unmarshalling to data which R type.
Types ¶
type BatchPlace ¶
type BatchPlace struct {
CityPlaces []CityPlace
}
func GeneratePlaces ¶
func GeneratePlaces(data BatchData) BatchPlace
type CityRequest ¶
type DataCityReq ¶
type DataCityReq struct {
Data []CityRequest `json:"data" validate:"required"`
}
type DataDistrictReq ¶
type DataDistrictReq struct {
Data []DistrictRequest `json:"data" validate:"required"`
}
type DataVillageReq ¶
type DataVillageReq struct {
Data []VillageRequest `json:"data" validate:"required"`
}
need to be seperated due different JSON struct tag
type DirectionH ¶
type DirectionH int
const ( East DirectionH = 1 West DirectionH = 2 )
horizontal shift toward DirectionH constants (east or west) means longitude increased or decreased but latitude remains the same
type DirectionV ¶
type DirectionV int
const ( North DirectionV = 1 South DirectionV = 2 )
vertical shift toward DirectionV constants (south or north) means latitude increased or decreased but longitude remains the same
type DistrictRequest ¶
type Location ¶
common attributes / structures
func RandShiftLoc ¶
Perform diagonal shift randomly from given location
func ShiftLoc ¶
func ShiftLoc(l Location, dist float64, dv DirectionV, dh DirectionH) Location
pure function, returning new object location based given direction and distance
type Place ¶
type Place struct { ID uint8 `json:"id"` // refers to building ownership in region CityName string `json:"city_name"` DistrictName string `json:"district_name,omitempty"` VillageName string `json:"village_name,omitempty"` CategoryID uint8 `json:"category_id"` Name string `json:"name"` Longitude float64 `json:"longitude"` Latitude float64 `json:"latitude"` }
Struct for response [GET] /search
func GetNearbyPlaces ¶
func GetNearbyPlaces(q WebQuery, bp BatchPlace) ([]Place, error)
assumption: the pinned location cant be surrounded by more than five cities. only scan places in closest cities.
type Regionable ¶
define region type, used in mapping
type Unmarshallable ¶
type Unmarshallable interface { DataVillageReq | DataDistrictReq | DataCityReq }
unmarshallable define type that would satisfy to unmarshall byte data from API
type Village ¶
type Village struct {
CoreInfo CoreInfo
}
structuring unmarshalled json from API call