Active
Project:
Geo
Version:
6.x-1.0-alpha5
Component:
Geo Field module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Jan 2010 at 15:45 UTC
Updated:
25 Jan 2011 at 15:29 UTC
Hi there,
does anyone knows if there is a way to extract the LON/LAT saved by Geo Field from the database? I used it to store Positions and now I need the positions in another DB table. Checking the field in content_type_MYTYPE table shows, that the data is stored as "geometry". Is there a way to get the lon and lat values from that?
Any help would be really appreciated!
Tom
Comments
Comment #1
allie mickaIdeally, you're using "straight drupal", and you can use the Lat / Lon formatters or view fields. If you really must access this information manually, you can do something like this:
SELECT X(field_MYFIELD_geo) AS lon, Y(field_MYFIELD_geo) AS lat FROM content_type_MYTYPE;
Comment #2
thommyboy commentedWow- that was a quick answer ;) Actually I need an SQL-solution because I need to put the "clean" data into another table
(I'm migrating data containing geo-fields to gmaps)
It worked well, thank you!
Comment #3
jonathan_hunt commentedI have a geo field storing a point, entered as lat lon. I've selected latitude in the CCK display field settings for the geo field but don't get any output on node view. Ditto for selecting longitude. Is there something I'm missing?
So, it's not clear that the lan/lon formatters work. If I have the node data, e.g.
how do I extract it?
Comment #4
jonathan_hunt commentedI guess this won't get attention if it's still closed...
Comment #5
bflora commentedIt's unclear how to use the lat/lon formatters. I'm in the same boat as Jonathan Hunt. I have a cck geo field that's getting LatLon fed into it. Now I need to know how to call to that data so I can put it where I want in my theme.
When I print out $node->field_coordinates[0][geo] I get a bunch of gibberish like in comment #3 above.
I suspect there are some functions in the geo module that I can run to output the actual lat/lon numbers. What are they and what exactly do I feed them? $node->field_coordinates? $node->field_coordinates[0]? $node->field_coordinates[0][geo]?
Thanks!
Comment #6
thommyboy commentedhi guys,
have a look at #1 and http://dev.mysql.com/doc/refman/5.1/de/point-property-functions.html the data is stored as geometry-type in mysql i think...
Comment #7
gagarine commentedDisplay a field using $node->field_XX[0][value] is never a good idea although it's a super common mistake. It's often a security issue except if you have a [view] in the array (that mean the node is already passed by the rendering functions). Read http://growingventuresolutions.com/blog/drupal-security
To build a single field use content_format
You can now use the long lat formatter as say Allie in #1.
P.S. @bflora I think putting a support request in major state is not so appropriate. If it's really critical for you, Allie Micka is certainly open for paid support...
Comment #8
bflora commentedHey gagarine,
Thanks for the tips on best practices. I appreciate it.
Can you give me an example of how to use the long lat formatter from #1? I understand I'm supposed to use that function, but I don't understand what I need to feed it. What does it take as an input. The function just says "$element" and that doesn't tell me much.
For example, I've tried adding each of these three tags to my templates.
print theme_geo_latlon($node);(generates a PHP error)print theme_geo_latlon($node->field_coordinates[0]);(nothing displays)print theme_geo_latlon($node->field_coordinates[0][geo]);(displays some non-English characters)So these function calls do not appear to be working. I've tried about 10 other variants and functions. If there's someone who knows how to do this properly, could they paste in the exact PHP code that would work for a geo field called field_coordinates? I can't find anything in the code or documentation that explains how to do this. Thanks.
Comment #9
gagarine commentedYou don't need to pass by the theme function but directly use content_format. So CCK do everything for you. That works with every CCK fields.
Formatters are declared in geo_field_formatter_info. Badly they are no latlon formatter but only one lat and lon. I make a patch about the lack of this formatter #596692: add geo microformat as output widget?.
So the code (I didn't try it but I hop it works ;) ):
field_coordinates need to be the name of your field of course.
Comment #10
bflora commentedI tried
and
And neither of them displayed anything. I checked and field_coordinates is the proper name for my field.
Other suggestions?
Comment #11
thommyboy commenteddid u try $formated_lat = content_format('field_coordinates', $node->field_coordinates[0][geo], 'lat');
Comment #12
bflora commentedThat threw a fatal error.
Comment #13
vlad.k commentedsubscribing
Comment #14
gagarine commentedOk perhaps they are a problem.
I change to bug because it sound wired for me but hop it's only a typo in my example or a problem with the @bflora's $node.
I will try soon. If nobody answer in 2-3 day just shout me a private message.
Comment #15
ahtih commentedI verified that the code above does indeed not work in many situations, because theme_geo_formatter_lat() expects input to be in Geo 'array' format, e.g.
In reality, in many contexts $node->field_geo_latlon is in different formats; for example, node_load() returns data like this:
..and in hook_nodeapi($op = 'update') it is in yet another format (which is a database-specific format returned by GeomFromText() function in geo_field($op='presave'); this is not WKB in neither MySQL nor PostgreSQL, although similar to WKB in both):
Comment #16
gagarine commentedI thinks I get where is the problem.
in geo.module the hook geo_nodeapi they is this code
So how I get it is than every field go at the end in this function to be converted before they are themed. I don't really understand why is like that.
Why not doing basic format transformation in geo_field.module in the hook_field on the load operation so other module can use the data. Those transformations cost a lot? If not we can imagine having more format in the field array...
Comment #17
gagarine commentedhere one way to get an array with lon and lat.