How would you display only the country name from an entry that has been geocoded with the fieldtype from the excellent Google Maps for ExpressionEngine (GMEE)?
I have discovered two ways of doing this which I thought might be helpful to someone, and am looking for improvements or better ideas if people have them.
Method 1.
Use a javascript plugin, as suggested by Justin Kimbrell, author of Google Maps for ExpressionEngine.
Method 2.
Use the extremely versatile 'Low Replace' ExpressionEngine plugin by Lodewijk Schutte:
{exp:channel:entries etc}
{geolocation parse="markers"}
{markers}
{exp:low_replace find="(.*,\s)(.*)" replace="$2" regex="yes"}
{marker:formatted_address}
{/exp:low_replace}
{/markers}
{/geolocation}
{/exp:channel:entries}
Notes:
- Non-essential code has been removed for brevity.
- 'geolocation' is the name of a GMEE fieldtype custom field
- The regex accounts for multiple place names in the format provided by Google Maps (e.g. "city, state, country" will be replaced by "country").
- Tested on EE v2.5.5 and GMEE v3.1.0