More efficient way to extract address components

前端 未结 9 1152
再見小時候
再見小時候 2020-12-15 10:23

Currenty, I\'m using the following code to get the country, postal code, locality and sub-locality:

var country, postal_code, locality, sublocality;
for (i =         


        
9条回答
  •  天命终不由人
    2020-12-15 10:57

    I did it like this:

    placeParser = function(place){
      result = {};
      for(var i = 0; i < place.address_components.length; i++){
        ac = place.address_components[i];
        result[ac.types[0]] = ac.long_name;
      }
      return result;
     };
    

    then i just use

    parsed = placeParser(place)
    parsed.route
    

提交回复
热议问题