Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Capturing GPS Coordinates When Picture Taken : Design Issue  RSS feed

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an implementation that works. However, just because it works doesn't mean it has been done properly. In fact, I'm sure it isn't correct but I had to get it working just in order to get it working. It has become technical debt because now I have to go back and do it right. Problem is, I'm not sure what is the correct way to this.

What I have so far is this:
1: A GPS Service that gets the lat,long and accuracy
2:CameraSurfaceView that extends SurfaceView and implements SurfaceHolder.Callback
3: A CameraActivity with a reference to the CameraSurfaceView

The CameraActivity creates a CameraSurfaceView in the onCreateMethod and adds it to the Activity's view.
The CameraActivity also has an ImageButton. When the ImageButton is pressed, I call the capture method inside the surface view.

When camera.takePicture is called, it triggers the callback method below (still in surface view)

holderActivity is the activity that contains the surface view. Yes, there is a cyclic relationship between the surface view and the camera activity. This is one aspect of the design I do not like, but I couldn't think of a better way to get the GPS Coords out from the surface view when the image is captured.

Overlooking the cyclic relationship for now, you will also notice that GPS.getLat() is a static call to the service in order to get the GPS Coords. This is the part that I am more concerned about. The service has a location manager and a location listener. The location manager requests location updates every second and in the onLocationChanged method, I simply set the values of the lat, longtd and accuracy directly. A call to GPS.getLat() gets the latitude at the time when the picture was taken...or at least the most recent value leading up to image capture.

This works, however, I do not think I should be accessing the service directly via static method calls since the service is riunning in it's own process thread. My goal is to make the service reusable outside of my application. I think this only works because the service is inside my application. The reason I need a service to do this is because I am writing a busness application that cannot wait 30 plus seconds for the device to get a fix on the location everytime an activity is opened up...otherwise I would have simply created the location manager and location listener directly inside the activity. The service is started at application startup and by the time the coordinates are required, the device has a fix on the location.

Should I have created a Service that I can bind to and get the coordinates from an aidl inerface? Or, should I create a service that broadcasts the coordinates when they change and then create a broadcast receiver to get the updates? Other suggestion?

Any advice would be appreciated.


It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!