|
70 | 70 | "cell_type": "markdown",
|
71 | 71 | "metadata": {},
|
72 | 72 | "source": [
|
73 |
| - "### 3. Latitude and longitude pairs from a list of cities\n", |
74 |
| - "\n", |
75 |
| - "<div class=\"alert alert-block alert-info\">\n", |
76 |
| - "\n", |
77 |
| - "**See also**\n", |
78 |
| - "\n", |
79 |
| - "* [Location APIs](https://locationiq.com/)\n", |
80 |
| - "</div>" |
| 73 | + "### 3. Latitude and longitude pairs from a list of cities" |
81 | 74 | ]
|
82 | 75 | },
|
83 | 76 | {
|
|
86 | 79 | "metadata": {},
|
87 | 80 | "outputs": [],
|
88 | 81 | "source": [
|
| 82 | + "from geopy.geocoders import Nominatim\n", |
| 83 | + "\n", |
89 | 84 | "def get_lat_long(address):\n",
|
90 |
| - " resp = requests.get(\n", |
91 |
| - " \"https://eu1.locationiq.org/v1/search.php\",\n", |
92 |
| - " params={\"key\": \"92e7ba84cf3465\", \"q\": address, \"format\": \"json\"},\n", |
93 |
| - " )\n", |
94 |
| - " if resp.status_code != 200:\n", |
95 |
| - " print(\"There was a problem with your request!\")\n", |
96 |
| - " print(resp.content)\n", |
97 |
| - " return\n", |
98 |
| - " data = resp.json()[0]\n", |
| 85 | + " loc = Nominatim(user_agent=\"Geopy Library\")\n", |
| 86 | + " getLoc = loc.geocode(address)\n", |
99 | 87 | " return {\n",
|
100 |
| - " \"name\": data.get(\"display_name\"),\n", |
101 |
| - " \"lat\": float(data.get(\"lat\")),\n", |
102 |
| - " \"long\": float(data.get(\"lon\")),\n", |
| 88 | + " \"name\": getLoc.address,\n", |
| 89 | + " \"lat\": getLoc.latitude,\n", |
| 90 | + " \"long\": getLoc.longitude\n", |
103 | 91 | " }"
|
104 | 92 | ]
|
105 | 93 | },
|
|
111 | 99 | {
|
112 | 100 | "data": {
|
113 | 101 | "text/plain": [
|
114 |
| - "{'name': 'Berlin, 10117, Germany', 'lat': 52.5170365, 'long': 13.3888599}" |
| 102 | + "{'name': 'Berlin, Deutschland', 'lat': 52.510885, 'long': 13.3989367}" |
115 | 103 | ]
|
116 | 104 | },
|
117 | 105 | "execution_count": 4,
|
|
154 | 142 | {
|
155 | 143 | "data": {
|
156 | 144 | "text/plain": [
|
157 |
| - "[{'name': 'Seattle, King County, Washington, USA',\n", |
| 145 | + "[{'name': 'Seattle, King County, Washington, United States',\n", |
158 | 146 | " 'lat': 47.6038321,\n",
|
159 |
| - " 'long': -122.3300624},\n", |
160 |
| - " {'name': 'Miami, Miami-Dade County, Florida, USA',\n", |
| 147 | + " 'long': -122.330062},\n", |
| 148 | + " {'name': 'Miami, Miami-Dade County, Florida, United States',\n", |
161 | 149 | " 'lat': 25.7741728,\n",
|
162 | 150 | " 'long': -80.19362},\n",
|
163 |
| - " {'name': 'Berlin, 10117, Germany', 'lat': 52.5170365, 'long': 13.3888599},\n", |
| 151 | + " {'name': 'Berlin, Deutschland', 'lat': 52.510885, 'long': 13.3989367},\n", |
164 | 152 | " {'name': 'Singapore', 'lat': 1.357107, 'long': 103.8194992},\n",
|
165 |
| - " {'name': 'Wellington, Wellington City, Wellington, 6011, New Zealand',\n", |
| 153 | + " {'name': 'Wellington, Wellington City, Wellington, 6011, New Zealand / Aotearoa',\n", |
166 | 154 | " 'lat': -41.2887953,\n",
|
167 | 155 | " 'long': 174.7772114},\n",
|
168 |
| - " {'name': 'Beirut, Beirut Governorate, Lebanon',\n", |
169 |
| - " 'lat': 33.8959203,\n", |
170 |
| - " 'long': 35.47843},\n", |
171 |
| - " {'name': 'Beijing, Dongcheng District, Beijing, 100010, China',\n", |
172 |
| - " 'lat': 39.906217,\n", |
173 |
| - " 'long': 116.3912757},\n", |
174 |
| - " {'name': 'Nairobi, Kenya', 'lat': -1.2832533, 'long': 36.8172449},\n", |
| 156 | + " {'name': 'بيروت, البسطة التحتا, باشورة, محافظة بيروت, لبنان',\n", |
| 157 | + " 'lat': 33.88922645,\n", |
| 158 | + " 'long': 35.50255852895232},\n", |
| 159 | + " {'name': '北京市, 中国', 'lat': 40.190632, 'long': 116.412144},\n", |
| 160 | + " {'name': 'Nairobi, Kenya',\n", |
| 161 | + " 'lat': -1.3026148499999999,\n", |
| 162 | + " 'long': 36.82884201813725},\n", |
175 | 163 | " {'name': 'Cape Town, City of Cape Town, Western Cape, 8001, South Africa',\n",
|
176 |
| - " 'lat': -33.928992,\n", |
177 |
| - " 'long': 18.417396},\n", |
178 |
| - " {'name': 'Autonomous City of Buenos Aires, Comuna 6, Autonomous City of Buenos Aires, Argentina',\n", |
179 |
| - " 'lat': -34.6075682,\n", |
180 |
| - " 'long': -58.4370894}]" |
| 164 | + " 'lat': -33.9288301,\n", |
| 165 | + " 'long': 18.4172197},\n", |
| 166 | + " {'name': 'Buenos Aires, Comuna 6, Ciudad Autónoma de Buenos Aires, Argentina',\n", |
| 167 | + " 'lat': -34.6083696,\n", |
| 168 | + " 'long': -58.4440583}]" |
181 | 169 | ]
|
182 | 170 | },
|
183 | 171 | "execution_count": 6,
|
|
236 | 224 | " distance = great_circle_dist(\n",
|
237 | 225 | " issloc.get(\"long\"), issloc.get(\"lat\"), loc.get(\"long\"), loc.get(\"lat\")\n",
|
238 | 226 | " )\n",
|
239 |
| - " logging.info(\"ISS is ~%dkm from %s\", int(distance), loc.get(\"name\"))\n", |
| 227 | + " logging.info(f\"ISS is {int(distance)}km from {loc.get(\"name\")}\")\n", |
240 | 228 | " return distance"
|
241 | 229 | ]
|
242 | 230 | },
|
|
261 | 249 | " return td.total_seconds()"
|
262 | 250 | ]
|
263 | 251 | },
|
| 252 | + { |
| 253 | + "cell_type": "markdown", |
| 254 | + "metadata": {}, |
| 255 | + "source": [ |
| 256 | + "The predictions for the `iss-pass` API are unfortunately no longer available, see[Open Notify API Server](http://api.open-notify.org)." |
| 257 | + ] |
| 258 | + }, |
264 | 259 | {
|
265 | 260 | "cell_type": "code",
|
266 | 261 | "execution_count": 11,
|
|
270 | 265 | "name": "stderr",
|
271 | 266 | "output_type": "stream",
|
272 | 267 | "text": [
|
273 |
| - "INFO:root:ISS is ~12639km from Berlin, 10117, Germany\n" |
| 268 | + "INFO:root:ISS is 3057km from Berlin, Deutschland\n" |
274 | 269 | ]
|
275 | 270 | },
|
276 | 271 | {
|
277 | 272 | "data": {
|
278 | 273 | "text/plain": [
|
279 |
| - "12639.759939298825" |
| 274 | + "np.float64(3057.10849285221)" |
280 | 275 | ]
|
281 | 276 | },
|
282 | 277 | "execution_count": 11,
|
|
0 commit comments