I've added locations to several node types using CCK. After using GMAP to set a node's location, I'd see the marker on the map would move after saving the new node.
The problem is that lat/lon were being rounded to six digits (not six decimal places). So if the lon was set to 123.456789 during node creation, if I submit and edit I'd see the value changed to 123.456000. After the submit it would always be changed to six digits, eg
0.123456 => 0.123456 (no change)
1.234567 => 1.234560
12.345678 => 12.345600
In the case 123.456789 => 123.456000, 0.001 degrees represents 111m so it's a noticeable movement.
The problem is something to do with conversion of string to float in db_query. The fix has been to stop using the float conversion by using the gmap_decimal function from the gmap module, as shown below. Can anyone see if there are any problems with this approach?
The other strange thing is that although I noticed it recently, it seems the problem has been happening for several months - but that before that it didn't happen. So I'm not sure which change introduced the problem.
Anyway, the fix was to edit the _location_save function in location.module, and change
db_query("INSERT INTO {location} (lid, type, eid, name, street, additional, city, province, postal_code, country, latitude, longitude, source) VALUES (%d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d)",
$lid,
$type,
$user_or_node->$field,
(!isset($posted_location['name']) || is_null($posted_location['name'])) ? '' : $posted_location['name'],
(!isset($posted_location['street']) || is_null($posted_location['street'])) ? '' : $posted_location['street'],
(!isset($posted_location['additional']) || is_null($posted_location['additional'])) ? '' : $posted_location['additional'],
(!isset($posted_location['city']) || is_null($posted_location['city'])) ? '' : $posted_location['city'],
(!isset($posted_location['province']) || is_null($posted_location['province'])) ? '' : $posted_location['province'],
(!isset($posted_location['postal_code']) || is_null($posted_location['postal_code'])) ? '' : $posted_location['postal_code'],
(!isset($posted_location['country']) || is_null($posted_location['country'])) ? NULL : $posted_location['country'],
$posted_location['lat'],
$posted_location['lon'],
$posted_location['source']
);
to
db_query("INSERT INTO {location} (lid, type, eid, name, street, additional, city, province, postal_code, country, latitude, longitude, source) VALUES (%d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
$lid,
$type,
$user_or_node->$field,
(!isset($posted_location['name']) || is_null($posted_location['name'])) ? '' : $posted_location['name'],
(!isset($posted_location['street']) || is_null($posted_location['street'])) ? '' : $posted_location['street'],
(!isset($posted_location['additional']) || is_null($posted_location['additional'])) ? '' : $posted_location['additional'],
(!isset($posted_location['city']) || is_null($posted_location['city'])) ? '' : $posted_location['city'],
(!isset($posted_location['province']) || is_null($posted_location['province'])) ? '' : $posted_location['province'],
(!isset($posted_location['postal_code']) || is_null($posted_location['postal_code'])) ? '' : $posted_location['postal_code'],
(!isset($posted_location['country']) || is_null($posted_location['country'])) ? NULL : $posted_location['country'],
gmap_decimal($posted_location['lat']),
gmap_decimal($posted_location['lon']),
$posted_location['source']
);
Comments
Comment #1
yesct commentedThis issue is over a year old, and there have been lots of improvements; I think it might be in the latest version. Could someone please confirm this in the latest version? I'll mark it as postponed (needs more info).
Comment #2
davidhk commentedI'm currently using 6.x-3.0, and the bug no longer exists in that version. I'm not sure if it still affects the 5.x version?
Comment #3
yesct commentedI'll go a head and mark this fixed, since it is working for the original poster by using 6.x, but if anyone can confirm it is still a problem in 5.x, please change the status back. :)