-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfetch_pokemon.go
More file actions
31 lines (28 loc) · 842 Bytes
/
fetch_pokemon.go
File metadata and controls
31 lines (28 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"fmt"
"time"
)
const (
GET_MAP_DATA_URL = "https://pokevision.com/map/data/%v/%v"
)
func FetchPokemonsInRegion(lat, lon float64) ([]Pokemon, error) {
data, err := RequestAPI(fmt.Sprintf(GET_MAP_DATA_URL, lat, lon))
if err != nil {
return nil, err
}
rawPokemons := data["pokemon"].([]interface{})
pokemons := make([]Pokemon, len(rawPokemons))
for index, unusableRawPokemon := range rawPokemons {
rawPokemon := unusableRawPokemon.(map[string]interface{})
pokemonId := int(rawPokemon["pokemonId"].(float64))
pokemons[index] = Pokemon{
ID: int(rawPokemon["id"].(float64)),
ExpiresAt: time.Unix(int64(rawPokemon["expiration_time"].(float64)), 0),
PokedexID: pokemonId,
Latitude: rawPokemon["latitude"].(float64),
Longitude: rawPokemon["longitude"].(float64),
}
}
return pokemons, nil
}