File size: 1,938 Bytes
c4d59c8 |
1 |
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"pip install geopy","metadata":{"execution":{"iopub.status.busy":"2024-08-15T14:13:12.568552Z","iopub.execute_input":"2024-08-15T14:13:12.568950Z","iopub.status.idle":"2024-08-15T14:13:29.912888Z","shell.execute_reply.started":"2024-08-15T14:13:12.568916Z","shell.execute_reply":"2024-08-15T14:13:29.911383Z"},"trusted":true},"execution_count":1,"outputs":[{"name":"stdout","text":"Requirement already satisfied: geopy in /opt/conda/lib/python3.10/site-packages (2.4.1)\nRequirement already satisfied: geographiclib<3,>=1.52 in /opt/conda/lib/python3.10/site-packages (from geopy) (2.0)\nNote: you may need to restart the kernel to use updated packages.\n","output_type":"stream"}]},{"cell_type":"code","source":"from geopy.geocoders import Nominatim\n\ndef find_location(location_name):\n geolocator = Nominatim(user_agent=\"location_finder\")\n location = geolocator.geocode(location_name)\n \n if location:\n return location.latitude, location.longitude\n else:\n return None\n \nif __name__ == \"__main__\":\n location_name = input(\"Enter the location name: \")\n location = find_location(location_name)\n \nif location:\n print(f\"Location: {location_name}\")\n print(f\"Latitude: {location[0]}\")\n print(f\"Longitude: {location[1]}\")\nelse:\n print(\"Location not found.\")\n \n","metadata":{},"execution_count":null,"outputs":[]}]} |