Drupal – Show a node location with Google Map in Views

We could add location information to node using the Location module. If the GMap module is enabled, we could even show the location with Google Map in Views.
1. Download and enable the GMap module.
 

2. Edit the Locative information of any content type. Make sure the Coordinate Chooser is set to Allow.

 

3. Create a view which shows the Location: Latitude and the Location: Longitude. Excluded them from display.
 

4. Create a Customfield: PHP code with the following value. (You need to install Views Custom Field)

<?php
  if ($data->location_latitude && $data->location_longitude) {
    print gmap_simple_map($data->location_latitude, $data->location_longitude, '', '', '17', 'default', 'default', TRUE, null);
  }
?>

 

5. The map will be shown only when the latitude and longitude of the node is set.
 

For more information about the gmap_simple_map(), please refer to the link below.

Done =)

Reference:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.