Closed (works as designed)
Project:
Geofield
Version:
7.x-2.x-dev
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Feb 2012 at 13:16 UTC
Updated:
2 May 2012 at 15:59 UTC
Wouldn't it be possible to render long distances as km and short distances as m?
The following example explains what i have in mind:
in geofield_handler_field.inc
function render($values) {
$metric = $values->{$this->field};
if ($metric >= 10) {
$distance = round($metric,0);
$distance_m = $distance." km";
}
elseif ($metric >= 0.5) {
$distance = round($metric,1);
$distance_m = $distance." km";
}
else {
$distance = round($metric,3);
$distance = $distance*1000;
$distance_m = $distance." m";
}
return $distance_m;
}(Unit of Measure: Kilometers)
Comments
Comment #1
Brandonian commentedGood idea @e_log! I'll happily accept patches that accomplish this in a configurable manner.
Comment #2
e_log commentedWe took a different approach to realize this. Since pages with individual distances are not cacheable (correct me if i'm wrong) we calculated the distance with JavaScript from a WKT field (with a readable output). The downside is of course, its not possible to order the nodes according to distance.
Comment #3
Brandonian commented@e_log, AFAIK, our views integration isn't doing anything that would hinder caching. Was there something in particular that made you think otherwise? If it's true, then we definitely need to fix it.
Comment #4
e_log commentedYou are right. Of course caching works if you use the distance field in views.
But we wanted to calculate the distance from the logged in user.
Sorry, i forgot to mention this important detail ;).
Our first idea was to overwrite the default values with geolocation values of the logged in user provided by the smart_ip module (see this thread: http://drupal.org/node/1445968). With this approach we would have had a caching problem because the distance field needed to be recalculated for every view of the node.
Now we calculate the distance from a node to the logged in user with JavaScript.
Comment #4.0
e_log commentedchanged wording for clarification.