Well, a PHP example, anyway

Once I dove in and started messing around, I only had to fix two typos as the example I was working on seems to work correctly, at least to the extent that I’ve tested it. I now have what appears to be a working example of Geostring parsing in PHP. In this case, the example reads my feed from the Twitter website, sifts out any geostring tags it finds, then generates Google Maps links for each one found. As I write this, there are two geostring tags on that page, representing places (and times)
that I have actually been, and it seems to work.

You can take a look at the source code for the example here, or see it in action here.

Feel free to grab a copy to play with if you’d like (or write one yourself that isn’t so messy – hey, as someone who doesn’t consider himself a professional “coder”, I’m just happy that it did exactly what I wanted it to do on the first try…). You should only need to worry about two things – changing the $text_to_read, and whether or not your web server (or CLI) has fopen wrappers turned on so the script can read another web page if you use a web page as your text to parse rather than a local file.

Since generating a geostring tag is trivial, I didn’t bother trying to incorporate that into this example. If you want one, then here:

//generate a geostr tag with the most typical information only
//point not part of a track nor including heading or angle
$elev=”1711.9m”; //could leave off the “m” and treat as float, since it defaults to “meters”
$timestamp=”20071125T123438-06″; //6 hours behind UTC

//”full” version: print(“geostr:$lat,$lon,$elev:$timestamp,:,:geostr”);
//completely unnecessary, but legal

As always, comments and suggestions are welcome.

Published by


The Author is (currently) an autodidactic student of Industrial and Environmental microbiology, who is sick of people assuming all microbiology should be medical in nature, and who would really like to be allowed to go to graduate school one of these days now that he's finished his BS in Microbiology (with a bonus AS in Chemistry). He also enjoys exploring the Big Room (the one with the really high blue ceiling and big light that tracks from one side to the other every day) and looking at its contents from unusual mental angles.

2 thoughts on “Well, a PHP example, anyway”

  1. I was very excited to see your string of posts about geotagging audio files! I am currently working for an artist who needs me to create a database of geotagged audio files. I would really love to include it in the actual metadata rather than in an external xml file or in the sqlite database. (I want it to be attached to the file b/c I am doing a separate google maps mod with the audio files.)

    I was sad to see the code example was incomplete ): Is there any working code examples you know of for adding the geostring tag? Also I am working with wav files. Would the process be any different??

  2. It’s a remarkable coincidence having you ask this, since right now I’m actually working on a short “Hacker Public Radio” episode on the subject of audio metadata (and am trying not to turn the fact that I haven’t gotten around to doing the specific Geotagging episode that I’ve been talking about for year into a running joke, while I’m at it).

    In light of some things that I’ve spotted along the way, for geotagging audio there’s only one specification that I know of, which is used by Ogg (Vorbis), Opus, Speex, and Flac. The tag takes the form of “GEO_LOCATION=(latitude);(longitude);(elevation in meters)“, with elevation being optional. If you can, you might be better off encoding the audio to lossless flac and using that. (I’ve turned into a huge Opus fanboy. It’s got amazing quality for the bitrate used, scales usably to remarkably low bitrates [usable for reasonable-quality speech all the way down to 6-10kbps!], and being chosen as a “mandatory-to-implement” codec for the WebRTC standard ought to help its adoption. Still, high-quality though it is, it’s still a lossy codec and flac would be a better choice for archiving.) flac is extremely popular among audiophiles so it seems to be very widely supported.

    (I like my format better as it optionally encodes a larger amount of useful information, but so far I’m still the only one that uses it, I think…)

    I’m not as familiar with the minimalist wav files, but they evidently can store some metadata in an “INFO” chunk. I’m not certain, but I think this is a relatively free-form text chunk, in which case you could also embed “GEO_LOCATION=(latitude);(longitude);(elevation)” in there as a “comment”, where it shouldn’t be difficult to automate extraction and copying to other files transcoded from the original .wav files. I know Audacity pops up with a box for entering metadata for exported .wav files, so I know it gets used from time to time. I’ll have to check to see if sox or similar utilities can be used to modify .wav metadata. Taglib also supports .wav metadata apparently, so anything built with that (such as the python2-based mutagen and various tag-editing programs) can probably handle it as well.

Leave a Reply