others

如何获取某个地点的经纬度

2019-01-18  本文已影响0人  小明的数据分析笔记本

投了一篇非常简单的论文,审稿意见中有一条 please give exact location of specimen collection preferably with geospatial coordinates;那么如何获得坐标呢?

Reference

根据参考文献2的方法获得百度地图API(API到底是个啥东西)
根据参考文献一的代码获得经纬度

代码也复制过来

import requests
def geocodeB(address):
    base = url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=json&key=f247cdb592eb43ebac6ccd27f796e2d2"
    response = requests.get(base)
    answer = response.json()
    return answer['result']['location']['lng'],answer['result']['location']['lat']

自己用的代码(完全照抄,改了一下API)

def geocodeB(address):
    base = url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=json&key=1hGi2uRbG7G4ZOviGfHF6ozqeo27WE7l"
    response = requests.get(base)
    answer = response.json()
    return answer['result']['location']['lng'],answer['result']['location']['lat']

查询自己的学校

In [96]: geocodeB("南京林业大学")
Out[96]: (116.355303, 40.013646)

查询学校科研教学基地

In [97]: geocodeB("南京林业大学白马教学科研基地")
Out[97]: (119.18552, 31.614207)

这相差的有点多呀!
再来看一下天安门广场

In [98]: geocodeB("天安门")
Out[98]: (116.403849, 39.915446)
和百度得来的没有差太多 58.PNG

为什么自己学校的科研基地和学校的位置会差好多呢?没太搞懂

咨询了实验室的一位师兄,得知通过google earth也可以获得对应地点的经纬度信息 Screenshot_2019-01-18-16-28-58.png
上一篇下一篇

猜你喜欢

热点阅读