Hi,

First of all, thank you for your outstanding work on an awesome module!

Is it possible to have the user's location show (via Gmap) within their profile page?

Currently, I have it set to show the location in the profile page, but all I get is a location header (h2 tag), with no info underneath. However, if I go to the edit tab for the user, the map does display with the user's location. This can't be a workaround however, because I cannot give all users access to edit each other's profiles. I do not believe this is a permissions issue, because the same issue happens when logged in as the super-user. I'm running drupal 5.7 with Location 5.x-3.x-dev and GMap version 5.x-1.0-beta1.

I'm attaching two screenshots, one showing the regular profile page, and the other showing the profile's edit page (showing the map).

Any help would be greatly appreciated!

CommentFileSizeAuthor
user-edit-tab.gif48.33 KBmherchel
profile.gif21.1 KBmherchel

Comments

NewZeal’s picture

Create a block at admin/build/block and insert the following code (Drupal 5) Make sure you select php input filter.

if (arg(0)=='user' && is_numeric(arg(1))) {
   $block = array();
    $result = db_fetch_array(db_query("SELECT latitude, longitude FROM {location} WHERE eid = %d AND type = 'user'", arg(1)));
    if (!$result) {
      return;
    }
    $macro = variable_get('gmap_location_block_macro_'. $node->type, FALSE);
    if (!$macro) {
      $macro = variable_get('gmap_location_block_macro', '[gmap |zoom=10 |width=100% |height=200px |control=Small |type=Map]');
    }
    $map = array(
      '#map' => 'gmap_location_authorblock',
      '#settings' => gmap_parse_macro($macro),
    );
    $map['#settings']['behavior']['notype'] = TRUE;
    $map['#settings']['markers'] = array();
    $map['#settings']['markers'][] = array(
      'latitude' => $result['latitude'],
      'longitude' => $result['longitude'],
      'markername' => variable_get('gmap_user_map_marker', 'drupal'),
      'label' => check_plain($node->name),
    );
    $map['#settings']['latitude'] = $result['latitude'];
    $map['#settings']['longitude'] = $result['longitude'];

    print theme('gmap', $map);
}
mrgoltra’s picture

Version: 6.x-3.x-dev » 5.x-3.0-rc2

Good Day,

I tried the code above but I am getting an error

user warning: Unknown column 'type' in 'where clause' query: SELECT latitude, longitude FROM cmmc_location WHERE lid = 1 AND type = 'user' in /hsphere/local/home/mysite.com/includes/database.mysql.inc on line 174.

Looking at the location table structure, there is no entry for eid. I do have lid. Any ideas?

Thank you,

Mark

NewZeal’s picture

The solution was for Drupal 5 not 6...

You'll have to debug the differences to get it to work in 6.

mrgoltra’s picture

I think original post is for 5.7? Thanks.

mrgoltra’s picture

The long way

The way I did it was to use advance profile kit + location module + nodeprofile + panels2 + gmap

once you configure all of the modules. In your user profile panel add the location map block.

apanag’s picture

@New Zeal

Thanks for the post man. I only changed this line:

$result = db_fetch_array(db_query("SELECT latitude, longitude FROM {location} WHERE eid = %d AND type = 'user'", arg(1)));

to this:

$result = db_fetch_array(db_query("SELECT latitude, longitude FROM {location} WHERE lid = %d", arg(1)));

Drupal 5.14

mherchel’s picture

That doesn't seem to be working for me. Did you have to do any additional config of the Location Map Block? I can't get it to work.

yesct’s picture

Status: Active » Postponed (maintainer needs more info)

mherchel, which fix did you try?

another idea to try: use content profile, and add a cck field to the profile to display the map. (maybe by adding a view that finds the location for the uid for content profile type nodes, maybe with a relation on content profile, and use a display of a gmap... I know that is a lot of maybe's)

Also, try using the latest dev version, there have been a lot of commits and it might be working better in there.

Post back if you are still wanting to get this to work.

mherchel’s picture

I was able to get this working using the code on http://drupal.org/node/205811#comment-1067358 in addition to the modifications within the following comment: http://drupal.org/node/205811#comment-1130586

Thx

yesct’s picture

Status: Postponed (maintainer needs more info) » Fixed
Issue tags: +location map on profile

marked #360759: Help with map display within profile as a duplicate of this one. (It has a pointer to another module that might help as an alternative.)

yesct’s picture

marked #396618: Display user's location in a block as a duplicate of this one

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tassoman’s picture

That code works using Drupal6 and the actual location module. The only problem is ballon it's empty. How to customize baloon's content?

<?php
if (arg(0)=='user' && is_numeric(arg(1))) {
   $block = array();
    $result = db_fetch_array(db_query("SELECT latitude, longitude FROM {location} JOIN {location_instance} using(lid) WHERE uid = %d", arg(1)));
    if (!$result) {
      return;
    }
    $macro = variable_get('gmap_location_block_macro_'. $node->type, FALSE);
    if (!$macro) {
      $macro = variable_get('gmap_location_block_macro', '[gmap |zoom=10 |width=100% |height=200px |control=Small |type=Map]');
    }
    $map = array(
      '#map' => 'gmap_location_authorblock',
      '#settings' => gmap_parse_macro($macro),
    );
    $map['#settings']['behavior']['notype'] = TRUE;
    $map['#settings']['markers'] = array();
    $map['#settings']['markers'][] = array(
      'latitude' => $result['latitude'],
      'longitude' => $result['longitude'],
      'markername' => variable_get('gmap_user_map_marker', 'drupal'),
      'label' => check_plain($node->name),
    );
    $map['#settings']['latitude'] = $result['latitude'];
    $map['#settings']['longitude'] = $result['longitude'];

    print theme('gmap', $map);
}
?>
neillodwyer’s picture

Same here... code from post #9 worked a treat. Thanks everyone.