The Young Persons Guide...

...to Becoming a Mobile Developer!

Page 2 of 4

I got a job

So I started a new job on Monday. Its an intern role with a startup company based in Dublin. Obviously my intention is to go back to college in late September/early October so its really only a summer job.
Anyway, the company deals with making apps. They’re making a security app for keeping children safe. Basically the phone uploads their coordinates to a server and the parents can see where their children are, as well as who they’ve been in contact with via phone or text.

There are 2 versions of the app, the android version and the blackberry version. I have been given the responsibility of making the Blackberry app. There’s an existing codebase there with bits of functionality but I’ll have to add most of it myself.

I’ll keep you updated on how the job goes.

Exam time

My exams start next week. I’m a little nervous to be honest. I don’t expect to fail anything and I’m pretty sure I’m guaranteed at least a bare bones pass degree based on my results from last semester and in-class tests during this semester, but still, its exam time! It always makes me nervous!

I’ve to go and get back to study now. I’ll update this blog after my exams, or when I get my results. wish me luck!

All finished!

So I handed up the project the other day and I had my presentation today.
The lecturers seemed impressed with the idea and commented on the marketability of it.I’m not sure if any other app exists with this type of functionality, but I’m sure thats just because I havent looked hard enough!! In terms of marketing the app, I don’t think thats going to happen. JC Decaux have their own official app, and I saw an article where someone nearly got sued for just releasing a similar app, so I don’t want that hassle. I might change my mind in the future, especially if I bother with the android version!

The presentation went well anyway. I’ve to wait a month or so now for the results, but with my exams about to start next week, I’m focusing more on them for the moment!

Getting the nearest point using GPS coordinates

One obvious requirement of this app is to get the closest bike station, or LUAS stop etc etc. This is the feature I’ve been working on lately.

Inititally I was a bit worried when I stumbled across the Great-Circle distance and the Haversine Formula as I’m not a big fan of calculations. Its one of the reasons I went into programming….so I could get computers to calculate hard stuff for me!!!

Luckily, I stumbled across a python library that has it all done for you!! Brilliant! Its called Geopy and can be installed with easy-install. My host doesnt allow for easy-install installs for some reason so I had to do it another way. I had to modify the django.fcgi file to point to a folder I named “modules” which contained the geopy tar.gz and django did the rest! Easy! I know I’m not giving much specifics here, but I’d imagine every host is different so you’ll need to figure out your own hosts methods for installing libraries yourself.

Anyway, with geopy all you need are 2 coordinates. You call a function called “distance.distance(coords1, coords2).miles” and it returns the distance in miles.

Here’s my code to find the nearest station based on the values in my XML file.

def nearestcoords(request, coords="53.345633+-6.267014"):
 user_coords = coords.replace("+", ", ")        ## convert from "lon+lat" to "lon,lat"
 from googlemaps import GoogleMaps
 from geopy import geocoders
 from geopy import distance
 g = geocoders.Google()

 # read xml file
 file = open('lockup.xml','r')
 data = file.read()
 dom = parseString(data)
 rows = dom.getElementsByTagName("root")[0].getElementsByTagName("subroot")[0].getElementsByTagName("stations")

 # setup vars
 shortestStation="None"        # Store temp nearest station
 shortestDistance=""
 for row in rows:
     # Get coords for current record
     curr_coords=row.getAttribute("lat")+','+row.getAttribute("lng")
     # Get distance
     tempDistance=distance.distance(user_coords,curr_coords).miles
     # check if distance is nearer/less
     if tempDistance<shortestDistance:
         shortestDistance=tempDistance
         shortestStation=json.dumps(
         {'number': row.getAttribute("number"),
         'address': row.getAttribute("address"),
         'lat': row.getAttribute("lat"),
         'lng': row.getAttribute("lng"),
         'open': row.getAttribute("open")},
         sort_keys=True,
         indent=4)

 result = ( "["+shortestStation[:-1]+"]" )
 return HttpResponse(result)

Seems straight forward enough! Basically what I’m doing here is opening the XML file, reading the values into an array called “rows”, then looping through that array and comparing coordinates. If the distance is less than the previous distance, that now becomes the new “shortestStation”. I then store the details of that station as a JSON string, which is outputted at the end, ready for consumption!!

Next on the agenda is getting the nearest 3 stations! I’ve no idea how I’m gonna manage this but we’ll see how I get on!

 

EDIT: After a few hours, and some helpful advice from the friendly folks at StackOverflow, I’ve manged to get this part working!

def nearestcoords(request, coords="53.345633+-6.267014"):
    user_coords = coords.replace("+", ", ")	 ## convert from "lon+lat" to "lon,lat"
    from googlemaps import GoogleMaps
    from geopy import geocoders
    from geopy import distance
    g = geocoders.Google()

    # read xml file
    file = open('lockup.xml','r')
    data = file.read()
    dom = parseString(data)
    rows = dom.getElementsByTagName("root")[0].getElementsByTagName("subroot")[0].getElementsByTagName("stations")

    # setup vars
    shortestStation=""		# Store temp nearest station
    shortestDistance=""
    mypoints = []
    for row in rows:
	 # Get coords for current record
	 curr_coords = row.getAttribute("lat") + ',' + row.getAttribute("lng")
	 # Get distance
	 tempDistance = distance.distance(user_coords, curr_coords).miles
	 mypoints.append((tempDistance, row))

    mypoints.sort()
    #the three closest points:
    mythree_shorter = mypoints[0:3]
    for distance, row in mythree_shorter:
	shortestStation = shortestStation+json.dumps(
        	{'number': row.getAttribute("number"),
		 'address': row.getAttribute("address"),
		 'lat': row.getAttribute("lat"),
		 'lng': row.getAttribute("lng"),
		 'open': row.getAttribute("open")},
		 sort_keys=True,
		 indent=4)+","
    result = ( "["+shortestStation[:-1]+"]" )
    return HttpResponse(result)

Wooh!! Now I’m happy! I can put this feature down as DONE!! 😀

Project Progress Update

I just realised I havent updated my project progress on here in a while, and since this is the reason I actually made this blog, I thought I better do so now.

So, as of this moment, I have every single bike station in Dublin being populated onto the iPhone UIMapView. I also have a dummy set of coordinates for places to lock your bike up, once you rent it. Additionally, I have all the LUAS stops appearing on the map. This was super tedious, as I had to manually get the coordinates of each stop from Google Maps, which took me about 3 times to get them right since Google Maps decided to give me the wrong coordinates, only to be discovered when I consumed the XML data and populated the map. I created the XML file by hand too!

I also have details of individual stations/lockups but not LUAS stop, as I’m currently trawling through the BeautifulSoup documentation to find a way to convert HTML into XML/JSON so as to be readable from the existing code. Once I figure out how to strip <div class=”xx”>xyz</div> so as to keep the xyz part, I should be good to go!

The public server is up and running too. I set it up using Django as the server, using a RESTful service to expose each “view”. My views are written in Python, which I am starting to like a lot. Its a very powerful language!

Also, since there are about 42 bike stations, lots of lockups, and about 50 LUAS station, getting the nearest station is going to take ~50 requests to the Google Maps server. I will need to implement some sort of client side “coordinate maths” to actually get the closest, then send that to Google, and return the directions. Google imposes a “2500 request per day” for non-premium users. Since the server is actually using shared hosting, I think it filters by IP. Usually I get one try, and then the limit is used up. As its only a school project, I’m not too worried about this. Obviously if it was going public, I’d actually pay for a dedicated IP! I have other hosting with an Irish company, but unfortunately I don’t think they do Python/Django hosting.

So, on my TODO list:

LUAS: Get individual station details (in JSON)

Directions: Figure something out client side for measuring coordinates

Custom start point: As a follow on from the “Directions”, the user should be able to choose a start point, other than their own, and get directions from there to the “nearest” station/stop.

 

So, not much to go. The beta is due up tomorrow, then I have a couple of weeks to polish it off. I also have that Android app to develop too…

Android read sms inbox fields

While I was doing some work on an android app (possibly related to my previous post ;)) I came across a problem. Google don’t seem to want people messing with their SMS inbox, for whatever reason, so have decided to put as little documentation on their site as possible.

So, in order to retrieve data from an SMS inbox you need 3 things:

  1. The URI of the inbox
  2. A Cursor to traverse the texts
  3. Some idea of what fields will be returned by the cursor.

After some Googling, I have found that most people use the inbox URI like so:

Uri uriSms = Uri.parse(“content://sms/inbox”);
Cursor c = getContentResolver().query(uriSms, null,null,null,null);

I have tried this and it works, if you want to retrieve the texts that people have sent you, but not for ones you’ve sent.Here is the complete list of URI’s for SMS.

All: content/all
Inbox: content/inbox
Sent: content/sent
Draft: content/draft
Outbox: content/outbox
Failed: content/failed
Queued: content/queued
Undelivered: content/undelivered
Conversations: content/conversations

Others have said online, this is not the best way to do it. You can also use the built in SmsManager class but I haven’t had time to look at that yet. Hopefully its easy enough to use.

Next up is the cursor, which is easy enough, and is used as follows:

Cursor myCursor = getContentResolver(UriSMS,null,null,null);

The 2nd “null” here is for the fields you want to retrieve. Putting “null” is effectively like saying “SELECT * FROM inbox”. We can specify other fields to retrieve like “body” or “date” or “person” but what I had trouble with was actually finding documentation on which fields are available.

Which brings me to my 3rd point. There is a built in method on the cursor that can return the name of each field. Using this, I’ve made a list of what fields can be retrieved from the outbox.

Starting from myCursor(0) to myCursor(15):
0: _id  (long)
1: thread_id   (long)
2: address   (String)
3: person   (String)
4: date     (long)
5: protocol
6: read
7: status
8: type
9: reply_path_present
10: subject    (String)
11: body    (String)
12: service_center
13: locked
14: error_code
15: seen

So there ya have it. Some basic SMS retrieval info. I might update this when I look into the SmsManager class in more detail.

C ya.

Double Snap!!

As with everything in the world of IT, ideas move fast! And they get replaced with ideas even faster.

About 5 minutes after I posted my last blog entry, I joined up with another group of programmers, who are making an app. Its a good idea for an app, and I reckon it should be good experience and look good on my CV.

With this app, there is scope to market it, in cooperation with some marketing people who have expressed interest in it. Also, we will be entering it in a competition, sponsored by Vodafone, called App-o-vation. The winners of this get backing from Vodafone, who will then distribute it through their channels and make it available through their web store.

I can’t give too much away, but put simply…..watch this space!!

Snap!

So, after some further research into making a RESTful server on the Android, I have decided to make a game of “Snap” instead!

There’s a few reasons for not making the RESTful server, mainly that it would take too long to code, and I have a deadline next month for it to be submitted, which simply isnt long enough for research, design and coding, as well as testing.

So, enter “Snap! for Android“. A cool little 2-player game to test your skill and reflexes against either the computer, or another human player. So far I just have the basics, ie Main menu with a “New Game” button, that loads 2 “snap” buttons and a random card. Expect some code samples, screenshots, and possibly a beta (or alpha) soon.

Meanwhile, I must get back to making my iPhone app too…..

A little side project

Following on from my last post about RESTful services, I’ve recently gotten an Android phone (HTC Desire) and have downloaded the Android SDK to have a little play around with it. I’ve managed a simple “Hello World” app, but nothing more yet. I have another subject in college that deals with mobile computing where, as part of our grade, we have to develop a smartphone app.

As it stands, to test the project, there will be a need to commandeer either a college computer, or bring in my own laptop to demo the server backend, but ideally I’d like to combine both the year long project and this other mini-project and create a server on an Android phone, which is capable of running a RESTful service and spitting out XML to be consumed by the iPhone, or indeed any client running on the network that is capable of displaying Google Map data.

So, this would be handy for 2 reasons:

  1. I always have my Android phone on me.
  2. I wont need to bring my laptop to college.

If this is possible, it would really look good on my CV, and would probably be something that would get a lot of downloads on the Android Market….which would nicely pad out my CV more, and kick start my portfolio, which at the moment is depressingly empty!! 🙁

However, if its not possibly, or feasibly for someone with basic knowledge, such as myself, then I suspect a little game of SNAP on the Android might be “on the cards…”!

RESTful services, XML and JSON

As this project has gone on, as expected, we have been adding features. So far, along with the core bike rental system features, there is now plans for LUAS integration, a map of secure bicycle lock-up facilities and possibly cycle lane support too.

As all the info relating to the bike stations (availabile number of bikes, location etc etc) is retrieved from one location, there will be a need to create another data source containing the info for these new features. As its only a college project, proof of concept is only needed, meaning the data does not have to be correct, it just needs to work, and pull back some info, be it dynamic or static. However, if some new official, correct, data source was found, simply changing the location to where the parser is pointing would then make it a fully functional, accurate piece of software! Until that day comes, a customised backend running a RESTful service will have to suffice.

Lets take the secure bike lock-up facility as an example here. There are no known (to me) sources at this time that contain the locations of any bike parking facilities, so for the purposes of this project, these locations will have to be fabricated. This will be done by storing mock coordinates in a data source (which I’ll get to in a minute), then writing a RESTful web service, most likely in NetBeans, which will run off glassfish server, and serve the results in either XML or JSON format. I reckon XML will probably be best route here, even though, as far as I know, there is built in support for both formats in NetBeans/glassfish. I’m not sure if there are any performance gains in choosing JSON, but looking at the raw data from both, the XML seems a lot more readable with its tags, so I’m hoping its a lot easier to parse. Although, going back to what I just said a few lines back, there is built in support for both so I think either option is the same at the high level NetBeans deals with it. Feel free to correct me in the comments if JSON performs better.

Keeping with the XML line here, we will need to store these coordinates somewhere. For peace of mind, and transparency of functions, it is my opinion that storing the details of the bike lock-up facilities in an XML file will make it a lot easier to read (for humans at least) by having matching tags in the data source and the XML data produced by the server. We also have to take into account what the iPhone can handle. This whole RESTful service thing is something I’ve only been looking into for a matter of days, hence why I’m unsure about performance vs XML files, so I’m also unsure if any differences exist between how the iPhone will handle XML and JSON when parsing them and storing the coordinates as arrays of strings, so for arguments sake, and to keep in line with the rest of the project, XML will what I will be focusing on, except if I discover JSONs performance gains far outweigh XMLs, as above.

So, after a few minutes playing around with this, I’ve managed to get my own server running, and it was surprisingly easy! Luckily enough, as you know, Java is pretty popular, as is NetBeans, so there is plenty of documentation online. For example, the easiest, most straightforward guide I found is here: Getting Started with RESTful Web Services from the netbeans.org docs. In 10 minutes flat, you can have your own server running, complete with a sample database, serving out a choice of both XML and JSON, which works perfect on Firefox, Internet Explorer, even an Android phones stock browser….but unfortunately not Google Chrome. But as far as I know, when using the UIWebView in the iPhone SDK, the iPhone uses the Safari renderer to display the Google Maps themselves, rather than some Google provided solution, ie Chromiums renderer, so this browser incompatibility shouldnt be a problem….hopefully. I’ve no idea what the case is when using MapView in either iPhone or Android, but I’d imagine its some sort of JVM solution so should be fine.

« Older posts Newer posts »