将instagram位置ID转换为经度和纬度,以便我可以将其覆盖在Google Map上

关于位置,我有用于Instagram帖子的JSON文件:

  

“位置”:{“ id”:“ 794643567398395”,“ has_public_page”:true,“名称”:“麦迪逊广场花园”,“子弹”:“麦迪逊广场花园”,“ address_json”:“ { \“街道地址\”:\“ \”,\“邮递区号”:\“ 10001 \”,\“城市名称\”:\“纽约,纽约\”,\“区域名称\”:\“ \”, \“ country_code \”:\“ US \”,\“ exact_city_match \”:false,\“ exact_region_match \”:false,\“ exact_country_match \”:false}“}

在这里,如何将该位置ID转换为纬度/经度,以便可以将其叠加在Google地图上?

以上内容是本文的JSON格式:https://www.instagram.com/p/B1xEDA0llSq/

jyw114 回答:将instagram位置ID转换为经度和纬度,以便我可以将其覆盖在Google Map上

如果您想一次叠加一个标记,则可以通过编程方式使用MapsURL https://developers.google.com/maps/documentation/urls/guide

  

搜索-启动显示特定位置图钉的Google地图,   或执行常规搜索并启动地图以显示结果:   https://www.google.com/maps/search/?api=1&parameters

例如,

<!DOCTYPE html>
<html>
<body>    
<p>Instagram ID:</p>    
<p id="demo"></p>    
<script>
var myObj,address;
var x = [];

myObj = {
    "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\": \"\",\"country_code\": \"US\",\"exact_city_match\": false,\"exact_region_match\": false,\"exact_country_match\": false}"
    }

    address = JSON.parse(myObj.address_json);

    for (i in address) {
      if ((typeof address[i] == 'string') && (address[i] !== 'undefined')) {                                      
            x += address[i] + " ";
      }
    } 

    var res = encodeURI("https://www.google.com/maps/search/" + myObj.name + x);
    // window.open(res);
    window.location.href = res;

</script>    
</body>
</html>

编辑:如果您真的想为给定的Instagram帖子检索一对经纬度,则必须将解析后的地址发送给地址解析器,例如

https://developers.google.com/maps/documentation/geocoding/start

,但是您需要一个API密钥。

注意:由于不能保证给定名称仅存在一个位置(例如:世界上有多个麦迪逊广场花园名称的地方),因此最好将名称和地址同时发送给地址解析器在执行上面的代码:myObj.name + x

编辑2:

  1. Instagram位置ID并非某种 geohash ,其位置已在ID中进行了编码,以防万一OP可能会认为其他情况。

  2. 询问此问题时,您可能已经知道,Instagram位置终结点已被关闭。

https://www.instagram.com/developer/endpoints/locations/

,

我通过外部Geocode API做到了这一点。您发送子弹名称或位置名称,然后返回一个包含long和lat的json。 您需要获得自己的api_key。

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))
本文链接:https://www.f2er.com/3162619.html

大家都在问