Keyword

Tutorial: Adding Googlemaps from k2 extra fields

  • Jesse Dundon
  • Jesse Dundon's Avatar Topic Author
  • Offline
  • New Member
More
15 years 6 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 5 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 5 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 5 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 5 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 5 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 5 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 4 months 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 3 months 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 3 months ago #70856 by troponin
Copy it !

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

  • Brad DiBaggio
  • Brad DiBaggio's Avatar
  • Visitor
15 years 3 months ago #70857 by Brad DiBaggio
Replied by Brad DiBaggio on topic Tutorial: Adding Googlemaps from k2 extra fields
Thanks, Jesse. Looking forward to using this.

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

More
14 years 11 months ago #70858 by Kwesi Raphael
Replied by Kwesi Raphael on topic Tutorial: Adding Googlemaps from k2 extra fields
Thanks a lot for the tutorial.
I found a slight error in it though, and thought I should let you know...

In your item.php.txt, "div class=googleMap" was inserted before the "php if" statement, which resulted in an empty map showing up on every page. I don't know if no one else got this problem, but I rechecked the files you've attached and the only comfort was that I can still follow instructions :)

Anyways, hope this helps.

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

More
14 years 11 months ago #70859 by James McCarthy
Replied by James McCarthy on topic Tutorial: Adding Googlemaps from k2 extra fields
You may want to consider using the Mosmap plugin instead of a K2 field - easier to use and much more functionality. Here's an example link in-sandiego.com/real-estate/commercial/for-lease/item/54-salon-day-spa-space-in-sorrento-mesa.html.

All you do is add {mosmap address='123 main street, anytown, anystate'} and that's it! Of course, there are a bunch of other settings you can add as well, but I set them all to default and pretty much use the same map style and zoom on my entire site.

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

More
14 years 11 months ago #70860 by Mike Dove
Replied by Mike Dove on topic Tutorial: Adding Googlemaps from k2 extra fields
Hi Thanks fo rthis Tutorial its helped me solve other problems I was having.

i have used your solution to call extrafield values into things such as div class="value" etc

i was wondering though if anyone knows if it is possible to split the results given by a mutli choice drop down box.

for example i have 3 divs and i want the class of each to reflect a single item from my multichoice selection.. anyway to split that data and call them seperatly? currently using this method produces a string of results seperated by a comma, what i want is each one seperate or as a series of li?

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

More
14 years 10 months ago #70861 by strummsteel
Replied by strummsteel on topic Tutorial: Adding Googlemaps from k2 extra fields
Great tutorial, unfortunately, i want to use this for my news articles so that authors can have a location mini map and shows a blank map when the extra field isnt filled out. Also is the a way to hide the extra field in the display and just show the resulting map?

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

More
14 years 10 months ago #70862 by Mike Dove
Replied by Mike Dove on topic Tutorial: Adding Googlemaps from k2 extra fields
Anyone know a way to get the code to work for the K2 content Module? it works fine in articles and catagory layouts but isnt pulling the data when used in the module templates default.php

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

More
14 years 9 months ago #70863 by Hazar Volga Ekiz
Replied by Hazar Volga Ekiz on topic Tutorial: Adding Googlemaps from k2 extra fields
hi everyone
ı dont speak english very well soryy
first of all great tutorial thanks so much
ı try this tutorials syas but ı dont succes
please help me
my site
www.interexuk.com/index.php?option=com_k2&view=itemlist&task=category&id=338:standard-general-english-course&Itemid=189

ı dont get the extra fields value
Attachments:

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

  • Biolsi
  • Biolsi's Avatar
  • Visitor
14 years 9 months ago #70864 by Biolsi
The EXTRA Fields are a function of K2 and are configured per category in the administration section of K2. You need to have at least 1 extra field that lists the physical address that you would normally type into google maps to bring up the address. You can use 1 field with the address listed in it, or you can have 1 field for street address and another for city, state, zipcode, etc.

Hazar Volga Ekiz said:hi everyone ı dont speak english very well soryy
first of all great tutorial thanks so much
ı try this tutorials syas but ı dont succes
please help me
my site
www.interexuk.com/index.php?option=com_k2&view=itemlist&;...

ı dont get the extra fields value

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

  • Biolsi
  • Biolsi's Avatar
  • Visitor
14 years 9 months ago #70865 by Biolsi
Does anyone know if there is a simply way to get the map to display the pop-up with the pin? So that it shows the name and address next to the pin? I can see it if I click on the pin, but I would love for it to be there by default.

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

More
14 years 9 months ago #70866 by Samuel Strickland
Replied by Samuel Strickland on topic Tutorial: Adding Googlemaps from k2 extra fields
Hello,
I've been watching this discussion for over 6 months now, and have tried the extra fields method. It works, however, it's a lot of extra work. SO, I tried every maps plugin I could find and I found that this - extensions.joomla.org/extensions/external-contents/maps-a-lo... works the best and with the least amount of time consumption.

The support from Mike Reumer (website) is fantastic, his site has very well documented instructions. I have over 60 maps on the site I'm currently working on, all in K2 content, all with custom API data on external KML files.

It allows for the most simple of maps or the most complex, allowing the use of external KML files and all Googlemaps API language. You can easily put maps into modules and numerous times into the same item, category, etc.

@Mike Bilosi - try the plugin, it has the option to make the pop-up display in the plugin parameters.

Hope this helps! I know it made my site building easier.

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


Powered by Kunena Forum