Adding gmap markers programmatically with a module I've been researching how to add markers to a drupal 7 gmap for more hours than I feel comfortable admitting. The reason I have to do it through a module and not views is because of client specifications that I won't go into here. The code below is what I have so far, everything I've found seems to point in this direction and it looks right to me. But when I go to the page, no markers show on the map. Can anyone help me out here?

function rrs_custom_menu() {
$items = array();
$items['search-by-towns'] = array(
    'title' =&gt; 'Search by Towns',
    'page callback' =&gt; 'search_by_towns',
    'access arguments'  =&gt; array('access content'),
    'type'  =&gt; MENU_CALLBACK,
);

return $items;
}
function search_by_towns() {
$query = "SELECT node.title AS node_title, location.lid AS location_lid, location.latitude AS gmap_lat, location.longitude AS gmap_lon, location.name as loc_name, location.street, location.city, location.province, location.postal_code, gmap_taxonomy_node.marker AS gmap_node_marker, taxonomy_term_data.tid AS tid, taxonomy_term_data.vid AS vid, gmap_taxonomy_term.marker AS marker
    FROM 
    {node} node
    LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid
    LEFT JOIN {location} location ON location_instance.lid = location.lid
    LEFT JOIN {gmap_taxonomy_node} gmap_taxonomy_node ON node.vid = gmap_taxonomy_node.vid
    INNER JOIN {taxonomy_index} taxonomy_index ON node.nid = taxonomy_index.nid
    INNER JOIN {taxonomy_term_data} taxonomy_term_data ON taxonomy_index.tid = taxonomy_term_data.tid
    LEFT JOIN {gmap_taxonomy_term} gmap_taxonomy_term ON taxonomy_term_data.tid = gmap_taxonomy_term.tid
    WHERE (( (node.status = '1') AND (node.type IN  ('listing', 'town')) AND (taxonomy_term_data.vid = '3') ))
    ORDER BY tid desc";


    $result = db_query($query);
    $marker = array();

    foreach ($result as $res) {
        $text = '&lt;div class="location vcard"&gt; &lt;div class="adr"&gt; &lt;span class="fn"&gt;'.$res-&gt;loc_name.'&lt;/span&gt; &lt;div class="street-address"&gt; '.$res-&gt;street.' &lt;/div&gt; &lt;span class="locality"&gt;'.$res-&gt;city.'&lt;/span&gt;, &lt;span class="region"&gt;'.$res-&gt;province.'&lt;/span&gt; &lt;span class="postal-code"&gt;'.$res-&gt;postal_code.'&lt;/span&gt; &lt;/div&gt; &lt;div class="map-link"&gt; &lt;div class="location map-link"&gt;See map: &lt;a href="http://maps.google.com?q='.$res-&gt;gmap_lat.'+'.$res-&gt;gmap_lon.'"&gt;Google Maps&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;';

        $marker[] = array(
            'latitude' =&gt; $res-&gt;gmap_lat,
            'longitude' =&gt; $res-&gt;gmap_lon,
            'markername' =&gt; $res-&gt;marker,
            'offset' =&gt; 0,
            'text' =&gt; $text,
            'opts' =&gt; array(
                'title' =&gt; '',
                'highlight' =&gt; 0,
                'highlightcolor' =&gt; '#FF0000'
            )
        );
    }

    $map_array = array(
        'id' =&gt; "auto1map",         // id attribute for the map
        'width' =&gt; "685px",        // map width in pixels or %
        'height' =&gt; "480px",      // map height in pixels
        'latitude' =&gt; '36.10237644873644',    // map center latitude
        'longitude' =&gt; '-80.8758544921875',  // map center longitude
        'zoom' =&gt; 8,              // zoom level
        'maptype' =&gt; "Map",       // baselayer type
        'controltype' =&gt; "Small"  // size of map controls
    );
    $map_array['markers'] = $marker;

  $output = theme('gmap', array(
      'element' =&gt; array(
        '#type' =&gt; 'gmap',
          '#gmap_settings' =&gt; $map_array,
          '#input'  =&gt; FALSE,
          '#theme'  =&gt; 'gmap',
          '#children'   =&gt; '',
          )
        )
    );

return $output; 
}
I wouldn't even get that fancy. Just use drupal_add_js to send an array of markers to a page, then call drupal_add_js to call your basic javascript that instantiates your map. Gmap hasn't been updated for V3 of the Google Maps API (so you need to go get a key, and you need to update the key when you move sites) and I've found that it's easiest, especially if you only need it on one page, to just call your own stuff.

EDIT: Maybe an example will help.

I had to do something similar where I wanted custom markers based on a set of results. In my preprocess I did:

  foreach($variables['results'] as $key =&gt; $result) {
    $store = node_load($result);
    $markers[$key] = array(
        'latitude' =&gt; $store-&gt;field_lat[0]['value'],
        'longtitude' =&gt; $store-&gt;field_lon[0]['value'],
        'title' =&gt; $store-&gt;title,
    );
  }
  $settings['markers'] = $markers;

  /* Add in the settings first */
  drupal_add_js($settings, 'setting');
  /* Then add in the javascript to instantiate map */
  drupal_add_js($module_path . '/map.js');


Then in my map.js:

Drupal.behaviors.map = function(context) {

  var initialZoom = true;
  mapInit();
};

function mapInit() {
  /* Get the markers variable set in PHP */
  var markers = Drupal.settings.markers;


  var myOptions = {
    mapTypeId : google.maps.MapTypeId.ROADMAP,
    scrollwheel : false,
    draggable : false,
    disableDefaultUI : true
  };
  var mapElement = document.getElementById("map");
  var map = new google.maps.Map(mapElement, myOptions);
  /* Loop through my markers and add them to the map */
  $.each(markers, function(index, value) {
    var latlng = new google.maps.LatLng(value.latitude, value.longtitude);
    bounds.extend(latlng);
    var marker = new google.maps.Marker({
      position : latlng,
      map : map,
      title : value.title
    });
  });
}