Keyword

Tutorial: Adding Googlemaps from k2 extra fields

  • Jesse Dundon
  • Jesse Dundon's Avatar Topic Author
  • Offline
  • New Member
More
15 years 3 months ago #70847 by Jesse Dundon
Do you want to include google maps in your k2 listings? I noticed a few people requesting it, and since so I dug in and figured it out for myself, I figured I would share it with the community. So here it is. I don't have a demo because the site hasn't been released yet, but this should work just fine for everybody. Also, since we can't add in code to this forum :( i have attached the code as .txt files.

Goal: Automatically output a google map based on extra fields right underneath the item's body text.
Solution: Call the fields manually into the template and plug them into a google maps iframe

Step 1: Create extra fields for address, city, state, and zipcode
Step 2: Create a few sample items with the address info filled out for testing
Step 3: Open up components/com_k2/templates/default/item.php
Step 4: Around line 239, you will find a clearing div directly below the output for the introtext/full text that looks like this (code simplified because this forum won't allow it): div class=clr....
Step 5: Below the clearing div, you need to define the custom variable you will be using to grab the custom fields. Add in the php line from my first attachment. You can actually define that anywhere in the code as long as it is above the next step...
Step 6: Add in the div and google maps code I snagged from some random site and call each of your extra fields into it in the correct place. In this case, the number in square brackets [0] is the first field in the group, [1] is the second, etc. In my case, 0,1,3, and 4 corresponded to address, city, state, and zipcode. You need to adjust these numbers based on the ordering of your extra fields. See second attachment.
Step 7: Test it out to make sure it works. Then, adjust the width and height as needed (they appear twice in the code, once each for the iframe, and once each for the map itself). You can also use some css to adjust the googleMap div that contains the iframe.

Enjoy! My final item.php is attached as a .txt file too, check out lines 240-245.
Attachments:

Please Log in or Create an account to join the conversation.

More
15 years 2 months ago #70848 by David Mead
Replied by David Mead on topic Tutorial: Adding Googlemaps from k2 extra fields
I haven't implemented this yet, but thanks in advanced for the 'how-to'. :)

Please Log in or Create an account to join the conversation.

  • Biolsi
  • Biolsi's Avatar
  • Visitor
15 years 2 months ago #70849 by Biolsi
I tried this and have zero success. I even tried copying the code directly from the 3rd text file provided. No luck. Yes, I DID change the field numbers. Tried with the site online and offline. No map. Ideas? I have K2 version 2.1 installed... in case that makes a difference.

Please Log in or Create an account to join the conversation.

More
15 years 2 months ago #70850 by Steve k
anybody got this to work? are extra field variables supposed to be the extra field id that I see in the admin?

Please Log in or Create an account to join the conversation.

More
15 years 2 months ago #70851 by Steve k
oops. my bad. I'm using a rockettheme template and the item.php file you need to edit is in templates>rt_moxy_j15(my theme)>html>com_k2>templates>default. Thanks so much Jesse.

Please Log in or Create an account to join the conversation.

  • Biolsi
  • Biolsi's Avatar
  • Visitor
15 years 2 months ago #70852 by Biolsi
Thanks, Steve K! I had the same issue... that I am using RocketTheme template and had to edit the item.php file for the specific directory. Works great now!

One note: the extra field IDs are NOT the IDs that you see in the admin - it is the ORDER ID that you have. For instance, my address has an ID of 7 in the K2 admin, extra fields section. If I put [7] as the ID in the code it will not work. However, it is the FIRST item in the list of extra fields for that category, so if I put [1] it correctly grabs the address.

Please Log in or Create an account to join the conversation.

More
15 years 2 months ago #70853 by FeSys
Thanks, seems good idea.. I'll try that

Please Log in or Create an account to join the conversation.

  • Francisco Ferreira
  • Francisco Ferreira's Avatar
  • Offline
  • Junior Member
More
15 years 1 month ago #70854 by Francisco Ferreira
Replied by Francisco Ferreira on topic Tutorial: Adding Googlemaps from k2 extra fields
Thumbs up! It works great. Thanks a lot...

It took me a little bit to assign the right number to the fields, but I managed to do it on a trial and error basis...

Many thanks...

Francis

Please Log in or Create an account to join the conversation.

More
15 years 2 weeks ago #70855 by Samuel Strickland
Replied by Samuel Strickland on topic Tutorial: Adding Googlemaps from k2 extra fields
I am using a RocketTheme template - Mixxmag, and I do not have the com_k2 folder in my templates>rt_mixxmag_j15(my theme)>html> folder.... any ideas??

Samuel

Please Log in or Create an account to join the conversation.

More
15 years 2 weeks ago #70856 by troponin
Copy it !

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum