Hi I was trying to extract this (“Polk County”, “short_name” => “Polk County”)
in the 3rd row of this Hash but I can seem to get just the “Polk County”
this is my current code:
{% for county_hash in location.address_components %}
{% for county in county_hash %}
{{ county.long_name }}
{% endfor %}
{% endfor %}
{
"0" => {
"long_name" => "426", "short_name" => "426", "types" => ["street_number"]
}, "1" => {
"long_name" => "Swanee Drive", "short_name" => "Swanee Dr", "types" => ["route"]
}, "2" => {
"long_name" => "Livingston", "short_name" => "Livingston", "types" => ["locality", "political"]
}, "3" => {
"long_name" => "Polk County", "short_name" => "Polk County", "types" => ["administrative_area_level_2", "political"]
}, "4" => {
"long_name" => "Texas", "short_name" => "TX", "types" => ["administrative_area_level_1", "political"]
}, "5" => {
"long_name" => "United States", "short_name" => "US", "types" => ["country", "political"]
}, "6" => {
"long_name" => "77351", "short_name" => "77351", "types" => ["postal_code"]
}, "7" => {
"long_name" => "8238", "short_name" => "8238", "types" => ["postal_code_suffix"]
}
}
2
Answers
While I’m not clear on what exactly you are trying to ask here, the following code
will
return
a string of alllong_names
namely426 Swanee Drive Livingston Polk County Texas United States 77351 8238
like you mentioned in the comments.If you need to get just
Polk County
, you’ll have to use thewhere
filter:Thanks for the help,
This method works for me.
breadcrumbs