Sunday, December 16, 2012

Centering maps app on user

So now that I have a maps app working on my phone I want it to draw a little icon where my location is and center the map on it.  Getting the icon to draw wasn't too bad.  I basically just followed the code here:

SA google-maps-android-api-v2-and-current-location

It's a horrendous amount of nasty looking code but being a newbie I'm just happy to get it working.  Maybe I can find cleaner implementations once I'm a bit more comfortable.

The problem now is that I get an icon but the map centers on Africa.  Let's see if I can get it to center on the user...

Turns out this wasn't too bad.  Just had to add a couple more lines of horrible verbose code.  Here are the important lines:

The final result for looks like:

Seems to work OK.

First Android Maps App

OK so I'm trying to build my first Android app that's going to be heavily based on Google Maps for location.  It turns out to be kind of a pain in the ass to get setup so I'm just gonna take some notes on what I've done so far.

1) Ditch openJDK and get the Oracle JDK. This seems to be universally recommended for Android development. It's pretty straightforward but if you're feeling lazy then I think I used this guide.

2) Get the Eclipse ADT. I could have gone for IntelliJ for Android development but it seems much easier to just go with the flow and get the IDE already setup for it.  I'll still stick with IntelliJ for Scala stuff I think.

3) Use the SDK manager to download some additional stuff into the IDE including the Google Services which I think is required for building a maps app.

4) Follow these steps to get your key from the debug cert.

Going through the guides got me there eventually.  Now I have to figure out how to get the user's location...