doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 8 forks source link

Add a `countryCode` method to the Address model #104

Closed lindseydiloreto closed 3 months ago

lindseydiloreto commented 4 months ago

When working with a multi-lingual site, it's often helpful to know the country code of a given Address.

If the Address was completed automatically using the Autocomplete lookup, the raw value will contain a detailed breakdown of the Google data. The country code is contained within this data, however, it is buried pretty deeply within the nested array.

Currently, this is what is required to access the country code...

address.raw['address_components'][3]['short_name']

We could potentially add a new method to surface the country code more easily and safely....

address.countryCode()

This shouldn't be too tough, will try to slot it in with some other priorities! 👍

lindseydiloreto commented 3 months ago

Good news, this is now available in v4.5.0! 🎉

{{ address.countryCode }}

Instead of a method to dig through the raw value, we elevated the countryCode to be a full-fledged subfield.