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

问题描述 投票:0回答:1

关于位置,我有用于Instagram帖子的JSON文件,关于位置,其外观如下图:

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

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

以上内容是本帖子的JSON:https://www.instagram.com/p/B1xEDA0llSq/

json google-maps geolocation latitude-longitude instagram-api
1个回答
0
投票

[如果您想一次叠加一个标记,则可以通过编程方式使用MapsURLhttps://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密钥。

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

© www.soinside.com 2019 - 2024. All rights reserved.