python获取图片的经度、纬度代码
时间: 2024-06-15 18:02:53 浏览: 11
要获取图片的经纬度,可以使用Python的第三方库`PIL`(Python Imaging Library)和`exifread`。首先需要安装这两个库:
```bash
pip install pillow
pip install exifread
```
接下来,可以使用以下代码获取图片的经纬度:
```python
from PIL import Image
import exifread
def get_image_location(image_path):
with open(image_path, 'rb') as f:
tags = exifread.process_file(f)
lat = tags.get('GPS GPSLatitude')
lon = tags.get('GPS GPSLongitude')
if lat and lon:
lat = [float(x) for x in lat.values]
lon = [float(x) for x in lon.values]
return lat, lon
else:
return None, None
image_path = 'path/to/your/image.jpg'
latitude, longitude = get_image_location(image_path)
print(f'经度:{longitude}, 纬度:{latitude}')
```
将`path/to/your/image.jpg`替换为你的图片路径,运行代码后,你将得到图片的经纬度。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)