我怎样才能得到谷歌地图的位置名称? [英] How can I get google maps location names?

查看:107
本文介绍了我怎样才能得到谷歌地图的位置名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,在该网站中需要获取所有谷歌地图的位置,从国家名称到最小的村庄。这是在api中的任何地方?因为它无处可寻。

I'm building a site in which it is required to get all google maps locations, from countries names to the smallest village. Is this anywhere in the api? Because it is nowhere to be found.

推荐答案

您需要解析响应以获取数据,例如,如果您想获得国家和结果是通过调用反向Gecoding得到的结果对象:
https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding

You need to parse the response to get that data out, so for example if you want to get the country and results is the result object you get by calling the reverse Gecoding: https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding

然后,获取国家的功能将be:

Then the function for getting the country would be:

       function getCountry(results) {
         var geocoderAddressComponent,addressComponentTypes,address;
         for (var i in results) {
           geocoderAddressComponent = results[i].address_components;
           for (var j in geocoderAddressComponent) {
             address = geocoderAddressComponent[j];
             addressComponentTypes = geocoderAddressComponent[j].types;
             for (var k in addressComponentTypes) {
               if (addressComponentTypes[k] == 'country') {
                 return address;
               }
             }
           }
         }
        return 'Unknown';
      }

这篇关于我怎样才能得到谷歌地图的位置名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆