我是Django和Python的新手。我想做一个视图,用户可以在其中打开google地图(或类似的东西),在地图上选择一个位置(放一个图钉),然后从该位置获取经度和纬度以保存到数据库。我搜索了互联网,但对如何操作感到困惑
能否请您指导我在哪里看或使用什么?非常感谢您抽出宝贵时间来帮助我
科斯塔斯
Google有访问Google地图的API密钥
api_key = "Your private key for google map here"
address="address of the selected user"
api_response = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}'.format(address, api_key))
api_response_dict = api_response.json()
这将在地图上搜索地址,并从该变量中返回对api_response变量的响应,您可以访问上述地址的经度和纬度
api_response_dict = api_response.json() # this line used to covert the response into a dict format/json format
latitude = api_response_dict['results'][0]['geometry']['location']['lat']
longitude = api_response_dict['results'][0]['geometry']['location']['lng']
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句