我有Instagram帖子的JSON文件,关于位置,它们看起来如下:
"location":{"id":"794643567398395","has_public_page":true,"name":"Madison Square Garden","slug":"Madison Square Garden","address_json":"{\"street_address\":\",\"zip_code":\"10001\",\"city_name":\"New York,New York\","region_name":\"exact_region\umatch\":false,\"exact_country_match\":false}"}
这里,我如何将此位置ID转换为纬度/经度,以便它可以覆盖在谷歌地图上?
以上是本文的JSON:https://www.instagram.com/p/B1xEDA0llSq/
您可以使用instagram_private_api
python库来查找任何Instagram或facebook(我指的是META(位置id的纬度和经度
pip install instagram-private-api
from instagram_private_api import Client
USERNAME = 'YOUR_INSTAGRAM_USERNAME'
PASSWORD = 'YOUR_INSTAGRAM_PASSWORD'
location_id = 794643567398395
api = Client(USERNAME, PASSWORD)
api.location_info(location_id)
输出:
{'location': {'pk': 794643567398395,
'short_name': 'Madison Square Garden',
'facebook_places_id': 794643567398395,
'external_source': 'facebook_places',
'name': 'Madison Square Garden',
'address': '4 Pennsylvania Plaza',
'city': 'New York, New York',
'has_viewer_saved': None,
'lng': -73.993499279022,
'lat': 40.75050203785},
'status': 'ok'}
有关图书馆的更多信息,请阅读此处
我是通过外部Geocode API实现的。您发送slug名称或位置名称,然后返回一个包含long和lat的json。你需要有自己的apikey。
import urllib.request, urllib.parse, urllib.error
import json
import ssl
api_key = your_own_api_key
serviceurl = 'http://www.mapquestapi.com/geocoding/v1/address?'
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
address = input('Enter location: ')
parms = dict()
parms['key'] = api_key
parms['location'] = address
url = serviceurl + urllib.parse.urlencode(parms)
print('Retrieving', url)
uh = urllib.request.urlopen(url, context=ctx)
data = uh.read().decode()
print('Retrieved', len(data), 'characters')
try:
js = json.loads(data)
except:
js = None
#print(json.dumps(js, indent=4))
lat = js['results'][0]['locations'][0]['latLng']['lat']
lng = js['results'][0]['locations'][0]['latLng']['lng']
print('lat,lng', str(lat) +','+ str(lng))