Posted: January 6th, 2012 | Author: admin | Filed under: Coding | No Comments »
The site!
Ah yes, where it all began. So, as mentioned previously, quite a bit of the core functionality regarding getting flags on a map using the maps api had worked out. That had, however, been a pretty manual process; adding latitude and longitude by finding areas from the maps site, right clicking and copying and pasting the results into a database.
That wasn’t going to work here, as noone wants to waste any time, least of all me, uploading an image, and then working out exactly where it was I took the photo. Plus, the phone is happily embedding the information in the image for me, so that’s exactly what I did!
Well, most of the time. As discussed in part one, I was also sending rough GPS positioning along with the information that *should* be within the exif data. However, as also discussed, if I took the picture too quickly, then a lock may not be made, and the image would end up appearing in the middle of the ocean, or wherever 0:0 is. So, a quick test to see if there’s any exif data, and then fall back on the data passed in the parameters if it’s not there.
Firstly, get the exif data out of the image. PHP offers a built in function for this fortunately, so it’s as simple as uploading the image, getting the filename and then running:
$exif = exif_read_data(‘uploads/’.$filename);
And then running another function to drag out the GPS data. This was a achieved via a function that I found on the internet (sorry person who wrote this! I forgot to add attribution!)
function getGps($exifCoord, $hemi) {
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
$flip = ($hemi == ‘W’ or $hemi == ‘S’) ? -1 : 1;
return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
}
And then simply run this function on the two relevant parameters:
$lon = getGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
$lat = getGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
Once I had this, I then had enough information to add to the database. The title, lat, long and description.
Displaying the photos
So, the mechanism is now in place to be able to upload as many images as the user pleases, with the relevant information retained within a database. The next stage is to display the information.
Firstly, it had to be usable. If I upload thousands of images, I have a map of the world, with buttons all over the place, and that’s not usable. So, I decided to display only the images for a particular day. First things first, a dropdown with all dates contained within the database.
SELECT YEAR(timestamp) Y, MONTH(timestamp) M, DAY(timestamp) D FROM photos GROUP BY DAY(timestamp)
This outputs a grouped list of all dates, and then it’s a simple task to format the information, not only to allow you to search later on, but to display the images in a user readable way.
It defaults to today, so if there are images, you see them, and if there aren’t you get a little message telling you that there’s nothing to see here.
Selecting a date then makes a call to the database to and pulls out all the relevant information. It does so in a pretty json call for the links:
{photos: [{"text": "
<div class="photo"><a id="review_sidebar50" class="photoLink" onclick="showPhoto(0);return false;" href="#"><span>Description of the photo</span>
21 Aug 2011 02:17:22</a>
</div>", "id": "2011-08-21"}]}
and a pretty bit of xml for google maps:
Which, apparently, wordpress won’t allow me to post…
The former to create links through which the user may browse the images without having to click the markers themselves, and the latter to be consumed by the Gmaps api to generate the popups.
The links at the side flow the ‘journey’ by time and date order.
And that’s basically it, for now at least. I started getting a bit obsessed with some features, so there’s more there than strictly needs to be, and a lot missing.
Things I’d like to get rid of:
The annoying flash every time you change the date. Prior to this, I had it nicely ajaxing from one date to another, with some nice smooth scrolling within the map. Then, I decided that I wanted to be able to ‘bookmark’ the dates, so I could send people links of particular days. to do this without reloading the page is probably possible, but fucked if I could work it out.
The shitty look of the whole thing. Why can I not design for shit.
Things to add:
You see that slider at the top? that’s supposed to allow you to select start time as well as a date, just in case someone adds a zillion pictures or something. It currently does nothing.
To add to the concept of the ‘journey’ I wanted to add some lines that linked you from one marker to the next. I’m pretty sure this is possible, but I gave up before completing it.
Adding ‘user login’. obviously a huge one, this. Username, password, uploading images and adding their user id, so that you can login and upload your images, and not get them mixed up with someone else’s, and then link directly to photo days for a particular user. Well, someone else may want to use it.
ooh, loads of stuff, probably.
And that, as they say, is that. All that is left is a link to the site.
Here: http://photos.duncanmetcalfe.net/
Posted: January 5th, 2012 | Author: admin | Filed under: Coding | No Comments »
So! The first exciting post of this year will be about the little hobby app that I wrote at the tail end of last year, you lucky no-people-who-are-reading-this!
One of the mildly exciting things about owning an Android phone is that creating apps is infinitely easier than it is for the iPhone. Throw away any thoughts of having to fork out $99 a year simply to be allowed the privilege of installing applications on your own device; doing this, at least, is free for android.
Of course, *proper* coding still requires some kind of nous, so fortunately, there’s this brilliant framework called PhoneGap that does all the heavy lifting for you, at least as far as accessing some of the native APIS is concerned. All that’s needed is some understanding of javascript, and the rest is (reasonably) simple.
The revenge
Anyway, back to the app. This initially started as an idea I had after having had most of my possessions nicked from my local leisure centre and after failing to convince both them and the Police that this was a bad thing, started working on a website that would basically allow other victims to select their local leisure centre, and to then state exactly what had happened to them, so that people could be informed as to the least shittiest places to exercise at.
Sadly, I then had cold feet about the whole thing, imagining millions of people libelling their local centre, and me being personally responsible for it – dunno if this would even be the case or not btw – so I dropped the idea. In the mean time I had done enough to get a good idea how the google maps api worked, so at least something good cam eout of it.
A new beginning
And so, out of my pettiness grew a wonderful new idea. What if you had an app, where you took a picture with your telemaphone, and then upload it directly from it, for it to appear as a pointer on map on a website? It would be crazy cool! also, I don’t think i’ve acutally seen anything like it before, but then again, I hadn’t looked too far.
So anyway, next step was to create the phone app. Using the aforementioned Phonegap, I also added into the mix JQTouch, a simple library based around the brilliant jQuery that would make things reasonably pretty. Disclaimer: I am not a designer, so I gladly accepted as much help as I need from ‘middleware’ or whatever you want to call it.
Additionally, it also allowed me to pretend to have the more ‘pages’ in the index.htm file than just the one. This was basically down to my inner UX expert’s desire to separate the functionality from within the app; there would be one page for taking the picture and another for selecting and uploading the picture.
taking a picture was as simple as calling the photo app via a js call through a function:
function capturePhoto() {
//Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, fail, {quality: 20});
}
Note: I don’t actually think that the quality parameter actually does anything. or at least, it doesn’t on my phone.
Then, it was a case of selecting the image, and uploading it. Initially I considered automagically uploading whatever image you had just taken, but I didn’t do this for a couple of reasons:
1/ I wanted to allow people to upload a description along with the image.
2/ GPS, but more on that later.
Image section was pretty simple. once again, there’s a built in function for this kind of thing:
navigator.camera.getPicture(onPhotoURISuccess, fail, {
quality: 20,
destinationType: destinationType.FILE_URI,
sourceType: source
});
The extra parameters are simply there to place the selected photo into memory.
After that, it was simply a case of uploading the image. along with some key bits of information. Firstly, the description that the user had added was added to an array of ‘params’ that get uploaded with the image.
Other key information were the gps latitude and longitude. This was based on a check I asked the phone to do every time an action was done on the page, and also, was in fact in addition to the gps co-ords being sent within the exif data of the picture itself. The reason for this backup was simply because I wasn’t entirely sure if the co-ords would be sent with the photo all of the time; if you took the picture too quickly, a lock wasn’t made, and nothing would be sent.
Doing it as a backup also gave the user some good idea that a lock had been made – a small coloured square was displayed next to the to-be-uploaded photo – red for no, green for yes, if we had something to send.
So! that was basically that as far as the app was concerned. next up: the site!
Posted: January 5th, 2012 | Author: admin | Filed under: Uncategorized | Tags: A NEW BEGINNING | No Comments »
Something something end of the world something something write something else this year.
Posted: August 1st, 2011 | Author: admin | Filed under: Uncategorized | No Comments »
The predictably brilliant This American Life programme outdid themselves this week with an absolutely superb insight into the state of patents, and the usual litigation that follows them.
Whist in Europe, thing never got anywhere this bad, I’m kind of hoping that it stays that way after listening to the mess that the States has gotten itself into over this; having heard some of the fun stories surrounding mobile companies, and what a state that particular industry is, with everyone suing everyone else (exciting infographic below), I had no idea that this was effectively the tip of the proverbial iceberg.

courtesy of Mashable
Have a listen here – Link but basically, the conclusion of the programme is absolutely correct. That despite the best efforts of those companies who have amassed huge numbers of patents, there is no way that anyone could, with a straight face, argue that these actions will in any way increase ‘inventiveness’, but simply exist to act as ammunition in a war effort against other companies, and/or is a good, old fashioned shakedown against true inventiveness.
I certainly wouldn’t bet the farm on the fact, but here’s hoping that now the subject has in some way hit the mainstream, that software patents do die somewhat of a death, if only so that people on the other side of the pond don’t start getting ideas…
Posted: August 4th, 2010 | Author: admin | Filed under: Uncategorized | No Comments »
So yeah, shocking – GOOGLE WAVE…DEAD?!
What seemed like such a promising tool for the future, cut down in the prime of it’s life. In fact, did it ever get out of beta? I dunno. I gave up on it around the same time as everyone else, I suspect; when the novelty of real time chat in a browser, as opposed to within an IM window, wore off and people then tried to work out what it was actually for.
Still, as the post implies, most of the cool shit will undoubtedly be folded into new projects, and the collaborative stuff was built for Google Docs, where it should have been in the first place.
Posted: August 4th, 2010 | Author: admin | Filed under: Uncategorized | No Comments »
Time to have a bit of a better look at this whole, ‘blogging’ thing that’s popular with all the kids. Right, from now on, i’m going to post whatever crap comes into my head. You know, like a real blog.
Posted: May 1st, 2010 | Author: admin | Filed under: Uncategorized | No Comments »
Well, at least it’s not going to end up being the huge Conservative majority that everyone had been anticipating, although given the latest polls which show a significant lead for them at the moment, it certainly looks like it’s going to end up that way.
I can only assume that the conservatives method this time round of carpet bombing all and sundry with a different leaflet every day – although that may be the case around my parts, because it’s been a staunchly Lib Dem area ever since I’ve lived here, the incumbent has had to move on, so it’s all to play for, as it were, with new faces all round – is working on some people.
Well that, and scaring the populous into voting for you with promises that our currency would be worth nothing within hours of a hung parliament being called, despite promising earlier on in the debate that scare tactics wouldn’t be used, but I guess everything changes when things start looking bad for you.
And the end of the day, as they say, I shouldn’t really be surprised. Labour’s victory in ’97 was mostly down to Blair’s ability convince people who would typically vote Conservative, vote for him, which isn’t a particularly difficult job if your party’s ideals had been shaped to make the transition easy for the voter. Now, having been left down, those voters are going to return to their natural voting instincts, especially as Cameron has successfully stolen back some ideas from Tony and pals.
Anyway, it’s not all doom and gloom, the LIb Dems have proved that there’s still the potential for some left of centre politics in this country, which gladdens the heart, and hopefully they will receive such a high percentage of votes, if not actual seats, that Proportional Representation will be inevitable, come the next election. Oooh, the BNP may get power if PR is introduced – so fucking what – all that means is that politicians need to do a much better job of acknowledging people outside of the middle class voters that they seem to rely on constantly these days.
SO THERE.
p.s. vote Lib Dem
Posted: April 13th, 2010 | Author: admin | Filed under: Uncategorized | No Comments »
So, no sooner had I set up my ‘portfolio’ blog, than I went and got a full time job anyway, making the information side of this site useless. Oh well! And I still didn’t fix the issue with the background – it seemed like such a good idea at the time…
Posted: November 6th, 2009 | Author: admin | Filed under: Uncategorized | No Comments »
Well, given that I’ve been doing this for so long, it’s surprising, to me, at least, that I’ve never bothered getting around to starting a blog of my own. Reason being that so far, with all the social networking that most people do these days, there didn’t ever seem any need for it, although as I have now made the leap into the freelance market, it seemed as good a time as any to give it a go.