|
10 | 10 | },
|
11 | 11 | {
|
12 | 12 | "cell_type": "code",
|
13 |
| - "execution_count": 1, |
| 13 | + "execution_count": 7, |
14 | 14 | "id": "94284d6e",
|
15 | 15 | "metadata": {
|
16 | 16 | "vscode": {
|
|
21 | 21 | {
|
22 | 22 | "data": {
|
23 | 23 | "application/vnd.jupyter.widget-view+json": {
|
24 |
| - "model_id": "cf72e462ac2847b586c82d5738e01598", |
| 24 | + "model_id": "2fe473c94493460082701df614ff2268", |
25 | 25 | "version_major": 2,
|
26 | 26 | "version_minor": 0
|
27 | 27 | },
|
28 | 28 | "text/plain": [
|
29 |
| - "Map(center=[0.0, 0.0], layers=[RasterTileLayer()])" |
| 29 | + "Map(center=[0.0, 0.0], zoom=2.0)" |
30 | 30 | ]
|
31 | 31 | },
|
32 |
| - "execution_count": 1, |
| 32 | + "execution_count": 7, |
33 | 33 | "metadata": {},
|
34 | 34 | "output_type": "execute_result"
|
35 | 35 | }
|
|
38 | 38 | "from ipyopenlayers import (\n",
|
39 | 39 | " Map, RasterTileLayer\n",
|
40 | 40 | ")\n",
|
| 41 | + "import configparser\n", |
| 42 | + "import requests\n", |
| 43 | + "import unicodedata\n", |
| 44 | + "\n", |
41 | 45 | "m = Map(center=[0.0, 0.0], zoom=2)\n",
|
42 | 46 | "layer= RasterTileLayer()\n",
|
43 | 47 | "m.add_layer(layer)\n",
|
|
46 | 50 | },
|
47 | 51 | {
|
48 | 52 | "cell_type": "code",
|
49 |
| - "execution_count": null, |
| 53 | + "execution_count": 8, |
50 | 54 | "id": "6ecd0ff6-93f3-4cd8-bc0a-8520aab07a84",
|
51 | 55 | "metadata": {},
|
52 | 56 | "outputs": [],
|
53 |
| - "source": [] |
| 57 | + "source": [ |
| 58 | + "config = configparser.ConfigParser()\n", |
| 59 | + "config.read('../.env.ini')\n", |
| 60 | + "api_key = config['DEFAULT']['api_key']" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": 9, |
| 66 | + "id": "c2a997b5-3f80-4e9c-8956-5dba704f7eae", |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [], |
| 69 | + "source": [ |
| 70 | + "def get_country_from_coordinates_geoapify(**kwargs):\n", |
| 71 | + " lon = kwargs.get('lon')\n", |
| 72 | + " lat = kwargs.get('lat')\n", |
| 73 | + " url = f\"https://api.geoapify.com/v1/geocode/reverse?lat={lat}&lon={lon}&apiKey={api_key}\"\n", |
| 74 | + " \n", |
| 75 | + " response = requests.get(url)\n", |
| 76 | + " data = response.json()\n", |
| 77 | + " \n", |
| 78 | + " features = data.get('features', [])\n", |
| 79 | + " if features:\n", |
| 80 | + " first_feature = features[0]\n", |
| 81 | + " properties = first_feature.get('properties', {})\n", |
| 82 | + " country = properties.get('country', None)\n", |
| 83 | + " normalized_name = country.split(' ')[0]\n", |
| 84 | + " normalized_name = unicodedata.normalize('NFKD', normalized_name)\n", |
| 85 | + " normalized_name = normalized_name.encode('ASCII', 'ignore').decode('utf-8')\n", |
| 86 | + " print(f\"Country: {normalized_name}\")\n", |
| 87 | + "\n", |
| 88 | + "m.on_click(get_country_from_coordinates_geoapify)" |
| 89 | + ] |
54 | 90 | }
|
55 | 91 | ],
|
56 | 92 | "metadata": {
|
|
69 | 105 | "name": "python",
|
70 | 106 | "nbconvert_exporter": "python",
|
71 | 107 | "pygments_lexer": "ipython3",
|
72 |
| - "version": "3.9.19" |
| 108 | + "version": "3.12.4" |
73 | 109 | }
|
74 | 110 | },
|
75 | 111 | "nbformat": 4,
|
|
0 commit comments