Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
2 posts Page 1 of 1
I was recently asked by a client if this was possible:
Client inputs address (can be one field or multiple - city, state, zip, etc.)
Couch outputs a google maps link to that address.

For example, if I enter "123 Broadway New York, NY 10006" into google maps, I get this link: https://maps.google.com/maps?q=123+Broadway+New+York,+NY+10006&hl=en&sll=40.708771,-74.010912&sspn=0.010589,0.022724&t=h&hnear=123+Broadway,+New+York,+10006&z=16

I have a button on my websites that I want to link to each location in google maps

Turns out it is trivial to do so. All the parameters (and there are quite a few) that can be seen in the Google map URL above are optional except the address.
This is one way of creating the link:

Create an editable region of type 'text' (has to be 'text' because we want our address in a single line).
Suppose the name of the region is 'my_address' (if you use some other name, modify the code coming next).
Place the following code in the template where the link is to be outputted:
Code: Select all
<a href="<cms:php>echo 'https://maps.google.com/maps?q=' . urlencode( stripslashes("<cms:show my_address />") );</cms:php>">Google Map</a>

The generated link should lead to the proper map.
As a follow-up to this, I was able to simply use the following:

Code: Select all
<a href="https://maps.google.com/maps?q=<cms:show address />+<cms:show city />+Michigan" target="_blank">Map</a>


I have separate Street Address and City inputs. All of my clients are in Michigan, but you could easily add a state from a state dropdown also:

Code: Select all
<a href="https://maps.google.com/maps?q=<cms:show address />+<cms:show city />+<cms:show state />" target="_blank">Map</a>
2 posts Page 1 of 1