By ethanre on
I installed the Location module and the Gmap modules.. They work great.
I looked every where to find info on how to edit the default Node view in order to show the google map under the Node body. I cant figure this one out...
This worked: I used a code snippet to alter the body template. Content Types > Edit > Template tab > Affect body output check box > Body Template:
if ( ($location['latitude'] != 0) && ($location['longitude'] != 0) && ($teaser != 1) )
{
$homes=array('id' => 'outfittermap',
'zoom' => 8,
'width' => '300px',
'height' => '200px',
'type' => 'Map',
'latitude' => $location['latitude'],
'longitude'=> $location['longitude'],
'markers' =>
array( array('markername' => 'blue',
'latitude' => $location['latitude'],
'longitude' => $location['longitude']
))
);
$outfittermap = theme('gmap', array('#settings' => $homes));
print $outfittermap;
}
BUT, I rather not use code snippets to alter templates.. I want utilize the Gmap view. How do I use Gmap and Views?
Thanks
Comments
Great question: I would like to do the same
Hi
That is a great question. I would like to have gmaps in my Drupal sites to display various data too (pictures for instance).
Can you send us the link to your website?
Let us know how it goes,
Good luck
Marc.
Admin for Drupal Photography group http://groups.drupal.org/photography | Personal Site http://www.weiersmuller.org
Still Looking
My site is internal to my work place and not accessible via the internet,, sorry.
So far I have not found a solution that doesn't require coding.
Enable location map block
If you enable the location map block, then for any node that has latitude and longitude ( path: /node/xxx) , a gmap will be displayed. You can adjust the weight of the block or the region for showing the block, to display this in the order desired in relation to the rest of the content.
Good but not there yet
This works however all my blocks are either above or under the main body content.. the body content has links at the bottom like printer-friendly and terms and bookmarking..
If i use a block the map is shown below the body, below the bookmarking and terms links.
I want the map to show in the body, above the printer friendly and bookmakring links
Besides using blocks, the only solution I know is to hack a template or node.tpl.php.
I'm pretty sure altering a
I'm pretty sure altering a node template is the standard way to embed gmap map inside a node body, whether that node is in teaser mode or in full body mode. And you can use the built in gmap_simple_map() function which is part of gmap to display the map.
The other option is to use gmap macros which you can type directly in the body when you are editing a node. e.g:
[gmap zoom=3 |center=40,0 |width=300px |height=200px |control=Small |type=Map]
I think those are your two main options for using gmap.
Gmap in Views and Panels2 Works!
I'm please to announce that it is possible to show a gmap view in a panel opening up tremendous flexibility. Before we start I assume that you have installed the Views, Panels2, Gmap, and the Location modules, that your location module is working as expected and that you know how to create Panel Pages.
Lets start:
1) Create a View
To start we will create a new View, click on:
Administer > Site building > Views
On the Administer Views page click Add
Use these settings:
Name: node_map
Access: no change
Description: node gmap view
Provide Block: Check box
View Type: Gmap View
Node Per block: 1
Fields > Add these two: Location: Latitude and Location: Longitude
Leave the rest at default values
Next, for Arguments click Add.
Use these settings:
Type: Node: ID
Default: Return Page not Found
Ttile: %1
Option: equal
wildcard: %1
Filters: optional
Click Save
2) Create a Panels View
Now go to Panels > Views
From the drop list select: node_map
Click Create panel view
Use these settings:
Panel view name: node_map_panel_view
title: Map
view type: block
Required context: node
rest is default
Save your panel view.
3) Create a Mini Panel
Next, we want to create a mini panel.
Go to Administer > Panels > Mini panels
Click Add
Use these settings:
Layout tab: select layout, I use single column
Settings tab >
Mini panel title: node_map_mini_panel
name:node_map_mini_panel
Context tab > select Node from drop box click Add required context
Save your mini panel
Click Content tab >
Click the + button. You will see a Views section with an object titled 'Map'
Click on 'Map'
Click save
4) Use Panel Pages
Next, we want to edit or create a panel page and insert our mini panel.
Go to Admin > Panles > Panel page. Add the mini panel to the content section.
Make sure to have these settings:
Settings tab > Path: node/%
Context tab > Argument > select Node ID click Add argument
Save
You're done! ;)
Why did I create a mini panel? because we need to pass context to the view and that's done via the mini panel..
Are there other or better ways to show google maps in a Panel or with your node/page? I'm sure there are.
These instructions are also posted on useful talk.
Update
An update, the marker in this view->panelview-> minipanel-> panel solution is the default Drupal marker and even though I changed all the marker settings to another choice the default one still shows up.
One more issue with this solution, the gmap works well in FF but with IE the map is blank gray and not centered. pretty much changed all the settings with no change in IE6.
If you try to follow the steps above, let me know if you get the same issue in IE6.
Note that if you edit a template and use code to insert gmap that IE6 will be ok.
The method above did not
The method above did not work for me, unfortunately. But thanks for sharing your work.
----------------------------------------------------------------------
http://www.bwv810.com/
I am a writer, researcher and solo drupal freelancer.
Je peux communiquer en français. / Я могу общаться на русском языке.
Code it
I agree.
What I did is that I decided that placing the code in the node.tpl.php was the best way to go..
This the code I have, by no means is this the best code out there but it works for me:
I am developing a site
I am developing a site (bayhorse.us) and have used contemplate to create a template for the photo listing; I have inserted coding similar to what you have above in the template and themed it by altering the css.
My main page is map/node, and that displays a map with all listings, indicated by a marker.
What I would like to be able to do is to reproduce that same map (map/node) but on a smaller scale (smaller dimensions) that I could place elsewhere on the site.
This gives a solution to replicating the map/node display; http://drupal.org/node/158576
What I'd like to be able to do is to reduce the zoom so that the map appears smaller, but still displays the nodes represented by the markers.
----------------------------------------------------------------------
http://www.bwv810.com
I am a writer, researcher and solo drupal freelancer.
Je peux communiquer en français. / Я могу общаться на русском языке.
hello, i tried to use your
hello,
i tried to use your code, but can't get it working... i was trying to load a map on every node for which i have latitude and longitude, but can't actually get them.
i also tried to load the node and load the location by node lid, but no way (field_where is the name of the location field in the node):
it just prints out Array... like it couldn't load the location, but actually the lid is correct...
thanks for helping
fixed, i put your code
fixed, i put your code inside location.tpl.php ... in there it can load latitude and longitude... :)
thank you!
Search gives duplicate error
I get this error after searching shows nodes with gmaps from locations after putting this code in the location.tpl.php file
Above the search results I have this error message 2 or 3 times...
"Duplicate map detected! GMap does not support multiplexing maps onto one MapID! GMap MapID: outfittermap"
for mulitple locations
I had nodes that had multiple locations. The script you gave works great for a single location but if you want to display all the locations for the single node, all you have to do is add a simple 'foreach' and run through the locations (note that node->location is different than node->locations). Thought i would post the code incase someone else wanted to show multiple locations from a single node on a single map. I also think this is a little simpler than working with views and panels. (also since this was specific to only one content type, i used contemplate and just slipped this in at the bottom of the body)
hope this helps
Hi , Thanks for this
Hi , Thanks for this functions its really help me.
I have an issue with this, its working fine when i m using this on any block or any where in my function but having problem when ajax call this function its gives me error like "Javascript is required to view this map."
Request.open("GET",site_path+"?q=reservation/node_map/"+nid.value,true);
Ajax call this path and page callback call this function and it returns like this
Please check and tell me how can i solve this problem, I have spend lots of time on this issue....
Thanks.
--
Azhar uddin
Technical Lead
email : engr.azharuddin@gmail.com
skype : computer_jin
clickable
hi ethanre,
this is some great code.
Do you by the way know what I can do to make the markers clickable as well? is there an API reference for the outfittermap so I could add html/images and click events etc.
Thanks :)
Markers clickable
I think the answer to your question is here.
http://drupal.org/node/144536
Subscribing!
Subscribing!