Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 谷歌地理编码-如何使用RESTAPI从lat、lng获取参考或id_Node.js_Api_Google Maps_Rest_Google Maps Api 3 - Fatal编程技术网

Node.js 谷歌地理编码-如何使用RESTAPI从lat、lng获取参考或id

Node.js 谷歌地理编码-如何使用RESTAPI从lat、lng获取参考或id,node.js,api,google-maps,rest,google-maps-api-3,Node.js,Api,Google Maps,Rest,Google Maps Api 3,我已经在这件事上绞尽脑汁好几天了。。。 我正在使用Node.js对Google maps REST API进行http调用 我需要检查数据库中的位置记录,并使用lat、lng-查找给定分辨率中的谷歌位置id或参考-例如说“国家”或“行政级别1” 我发现这两个rest调用与我需要的最接近: https://maps.googleapis.com/maps/api/geocode/json? latlng=47.333333,13.333333 &sensor=false &key=

我已经在这件事上绞尽脑汁好几天了。。。 我正在使用Node.js对Google maps REST API进行http调用 我需要检查数据库中的位置记录,并使用lat、lng-查找给定分辨率中的谷歌位置id或参考-例如说“国家”或“行政级别1”

我发现这两个rest调用与我需要的最接近:

https://maps.googleapis.com/maps/api/geocode/json?
latlng=47.333333,13.333333
&sensor=false
&key=YOUR_API_KEY
&result_type=administrative_area_level_1 
此调用接收lat、lng和所需分辨率,并返回准确结果,但没有id或参考。。。 结果如下:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Salzburg",
               "short_name" : "Sbg.",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Austria",
               "short_name" : "AT",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Salzburg, Austria",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 48.04121,
                  "lng" : 13.9965099
               },
               "southwest" : {
                  "lat" : 46.94347,
                  "lng" : 12.07669
               }
            },
            "location" : {
               "lat" : 47.80949,
               "lng" : 13.05501
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 48.04121,
                  "lng" : 13.9965099
               },
               "southwest" : {
                  "lat" : 46.94347,
                  "lng" : 12.07669
               }
            }
         },
         "types" : [ "administrative_area_level_1", "political" ]
      }
   ],
   "status" : "OK"
}
到目前为止,我唯一的另一种选择是像这样使用autocomplete REST API:

https://maps.googleapis.com/maps/api/place/autocomplete/xml?
key=YOUR_API_KEY
&location=47.333333,13.333333
&sensor=false
&language=en
&types=(regions)
&input=Austria
这一个的问题是,因为它是为了自动完成的目的,它需要传递“输入”参数,而不仅仅是lat,lng,这对我来说更好。这是更好的,因为我试图处理的位置使用多种语言,为每个记录指定其语言将是一场噩梦

这是上一次调用的结果: 我需要迭代预测对象,并在我要寻找的分辨率中找到它们

{
   "predictions" : [
      {
         "description" : "Austria",
         "id" : "e16f8e9f2a60f60a0881c41488ff3869e4f938a4",
         "matched_substrings" : [
            {
               "length" : 7,
               "offset" : 0
            }
         ],
         "reference" : "CiQfAAAAF11VDI_p7OWWL8woW8cOfCDDeA0iE-NMQwQsbQhouSASECau8aTrkIVsiUcGrmnNHhwaFEmcUvCjjjsHRDznswqC_xeOYiBR",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Austria"
            }
         ],
         "types" : [ "country", "political", "geocode" ]
      },
      {
         "description" : "Lower Austria, Austria",
         "id" : "03ea5cab0b5abe4cb16f66e9a42c27d040ce2b3c",
         "matched_substrings" : [
            {
               "length" : 7,
               "offset" : 6
            }
         ],
         "reference" : "CjQuAAAAznpNXppnhg3bl-36bfMr4tsQa3ZjJJWmtUuHIEzEy4RL9M_LeSGc8muP-_h_e89gEhCFjfuwyex9OA36skw8bD45GhQ14NncFQk-AHOILKC4IqEPe-XqDw",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Lower Austria"
            },
            {
               "offset" : 15,
               "value" : "Austria"
            }
         ],
         "types" : [ "administrative_area_level_1", "political", "geocode" ]
      },
      {
         "description" : "Vienna, Austria",
         "id" : "f622c175d668fbf75e7488ddf7b1a04ecb667788",
         "matched_substrings" : [
            {
               "length" : 6,
               "offset" : 0
            }
         ],
         "reference" : "CjQnAAAAD88YSerev6ZNhRw6hI0P9g_Brsjzc_qN5PqKtugj7GXIMbhqKK1qvJXYprMFu67mEhDYSzeYQwEQFjnOxjb3SsxAGhTocUQpKtR1CoM7sYJJROGImDMQzQ",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Vienna"
            },
            {
               "offset" : 8,
               "value" : "Austria"
            }
         ],
         "types" : [ "locality", "political", "geocode" ]
      },
      {
         "description" : "Oberosterreich, Austria",
         "id" : "5ecb86bf53005b6cd7499f660e2312089a955ced",
         "matched_substrings" : [
            {
               "length" : 14,
               "offset" : 0
            }
         ],
         "reference" : "CjQvAAAAgtYVlhBFCDPBgcJu_7CXHJ8ncd3m6IozPSg3YzaLL4kXVtQowpjx4kc2K-Tqm_0YEhCn4rEiM0MaChwBhkki0qu_GhRgpGKjjh4Hq4aN2n9jFjdfc-Xl8Q",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Oberosterreich"
            },
            {
               "offset" : 16,
               "value" : "Austria"
            }
         ],
         "types" : [ "administrative_area_level_1", "political", "geocode" ]
      },
      {
         "description" : "Austrian District, Gyumri, Shirak, Armenia",
         "id" : "3948451df8a40142c1adeeeb4a969dc1c7d82d39",
         "matched_substrings" : [
            {
               "length" : 7,
               "offset" : 0
            }
         ],
         "reference" : "ClRCAAAANrMT8rQH819b7rtJiCbaq0XbDip8VuQCO7EvoIkVmg4xUyQtxGiFhm9sF52hTbtp8PjR-b0_dCLn-ZXceYfJJ64j1hwxbuthSHomBoGBphMSEPC8ZwPtn6dOrYb_duar-tcaFIFbhTX9HWS4UDzF2exZcw2YUh9o",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Austrian District"
            },
            {
               "offset" : 19,
               "value" : "Gyumri"
            },
            {
               "offset" : 27,
               "value" : "Shirak"
            },
            {
               "offset" : 35,
               "value" : "Armenia"
            }
         ],
         "types" : [ "sublocality", "political", "geocode" ]
      }
   ],
   "status" : "OK"
}
原始数据来自我们使用的geonames数据库。我们正在切换到在我们的应用程序的所有部分使用谷歌地图API的,因此我需要将这些转换为谷歌位置id的使用纬度,液化天然气和分辨率只。。。名字是我无法控制的,因为它们是已知的。在许多语言中

如果您能指出一个RESTAPI调用能够做到这一点,或者一系列http调用,我将不胜感激

谢谢。 Ajar

基于谷歌网站上的API,我建议使用以下API:

将地理位置的纬度/经度坐标转换为地址(反向地理编码)。
(网络服务)