2017-06-12 71 views
-1

我正在使用Google GeoCoding服务(使用浏览器的获取请求)并尝试获取干净的街道名称(例如,没有前/后方向和后缀) 例如:如果我的地址是“3307 W Bertona St Apt 3,Seattle,WA” 我想要得到的只是街道名称“Bertona”。 我的请求URL: https://maps.googleapis.com/maps/api/geocode/json?address=3307%20W%20Bertona%20St%20Apt%203%20%2C%20Seattle%20%2C%20WA%20%2C%20&sensor=false&client= {}的clientId签名& = {}专用密钥Google GeoCoding服务 - 获取干净的街道名称

有什么办法来检索服务清洁街道的名字吗?

回答

0

您可以在响应检索address_components阵列街道名称:

{ 
    "results":[ 
    { 
     "address_components":[ 
     { 
      "long_name":"3", 
      "short_name":"3", 
      "types":[ 
      "subpremise" 
      ] 
     }, 
     { 
      "long_name":"3307", 
      "short_name":"3307", 
      "types":[ 
      "street_number" 
      ] 
     }, 
     { 
      "long_name":"West Bertona Street", 
      "short_name":"W Bertona St", 
      "types":[ 
       "route" 
      ] 
     }, 

route类型的组件包含了长,短的街道名称。这是您可以从地理编码API请求获得的最干净的名称。