I discovered that you can append the Google Maps URL with a value in parentheses to supply a label for the marker (instead of "Address:"). The only drawback that I can see right now is that the functions that generate the links are country-specific, so you would have to change the function for each and every country where you want to implement this.
Note that the code I'm using is for generating links for Canadian addresses, and that I'm using locations attached to a node profile, so I made allowance to for the label to be the username of the user, instead of the name of the node. More about that last bit in a minute, but for now here is the revised link function that creates the label, in this case from location.ca.inc:
function location_map_link_ca_google($location = array()) {
$query_params = array();
foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) {
if (isset($location[$field])) {
$query_params[] = $location[$field];
}
}
$loc_label = '';
if ($location['name']) {
$loc_label = '+('. $location['name'] .')';
}
else if ($location['parent_label']) {
$loc_label = '+('. $location['parent_label'] .')';
}
if (count($query_params)) {
return ('http://maps.google.ca?q='. urlencode(implode(", ", $query_params)) . $loc_label);
}
else {
return NULL;
}
}
To add the 'parent_label' parameter, I altered the location_load_locations function (in location.module) as follows:
function location_load_locations($type, $node_or_user) {
$res = db_query("SELECT * FROM {location} WHERE type = '%s' AND eid = %d ORDER BY lid", $type, $type == 'user' ? $node_or_user->uid : $node_or_user->vid);
if (strcmp($type, 'user') == 0 || @is_nodeprofile($node_or_user->type)) {
$parent_label = $node_or_user->name;
}
else {
$parent_label = $node_or_user->title;
}
$locations = array();
$location = array();
$index = 0;
while ($row = db_fetch_object($res)) {
$locations[$index] = (array) $row;
if (isset($locations[$index]['latitude'])) {
$locations[$index]['lat'] = $locations[$index]['latitude'];
$locations[$index]['lon'] = $locations[$index]['longitude'];
}
if ($extra = location_invoke_locationapi($locations[$index], 'load')) {
$locations[$index] = array_merge($locations[$index], $extra);
}
$locations[$index]['parent_label'] = $parent_label;
$index++;
}
$location = count($locations) ? $locations[0] : array();
return array('locations' => $locations, 'location' => $location);
}
Now, wherever this change is implemented, each Google Map linked to will show the location name, if available, or show the name of the node or user it's attached to, if that's available.
Comments
Comment #1
mrgoltra commentedsubscribing
Comment #2
yesct commentedThis sounds really cool. The code above is a good start. If someone wants to create a patch to implement this, please do. (http://drupal.org/patch/create) I'll mark it postponed for now, because this might be an idea worth investigating in the future.
Comment #3
ankur commentedThis looks like something that would be straight-forward to add as a configurable option to anywhere that locations are displayed on a google map, though we'd probably want to do this without adding the above suggested code to location_load_locations()
Pushing to 7.x-4.x.
Comment #4
lylaburns123 commentedThank you for this information. I have been wanting to add a piano movers company to Google Maps. I can't wait to go try this out. Thanks again!
Comment #5
moesatriani commentedThank you so much for posting this. I have been wanting to add information to my dentist office for a long time. My brother, who is a genius at this, tried to walk me through it but I kept on getting lost. With your help, everything is becoming much easier to understand. Thanks again for all of your help!
Comment #6
justjordy33 commentedSeeing all these different things is very different. Gotta start thinking monuments now. monuments