SurfMap provides functionality that is to be part of the Surf Stoked app which was created as part of the Silicon Valley Android Developers Hack-a-thon held on 30 June - 1 July 2012:
Both the SurfMap application and full sources (as a zipped up Eclipse project) are available. Note: In order to install, the Android device or emulator must include the Google api's.
Surf Stoked was proposed as a surf spot sharing app. Able to send info on surf spots such as location, pictures, wave conditions, and current and wind directions to selected surfing buddies. Kim Hansen and Pedro Arelo are the surfers who proposed the app and were providing the main UI. Roberto de'Lirio was doing near field communications to exchange info with near by buddies. Jane Wang was a marketing person who was to help with the presentation of our app on Demo Night. My part was to provide GPS coordinates and display the location of surf info on a map. This project, SurfMap, is a stand alone version of the GPS and mapping parts. The MapView i create here is supposed to show up in Surf Stoked as a panel in the final ui.
Remaining Steps to Integrate SurfMap into the Surf Stoked App
The remaining task on my list is to be able to create a new record based on location. If you add a button to create the new record you can already get the location information. If you want to create a data point at any location on the map, you can scroll and zoom to the desired spot and get the location using MapView::getMapCenter. If you want to create the record at your currant location, use LocationManager::getLastKnownLocation.
I cleaned up my sources so there is now a routine to take SurfRecords and install them as icons on the map. For integration with the main app (is Surf Stoked the name of the main app?), SurfRecords will be replaced by the Surf Stoked records. The markers on the map are stored in the map overlay with the location and two strings. I thought one string would be the title and the second string should be a key that can be used to get back to the original Surf Stoked record stored in our surf location data base. For this sample, in the SurfItemizedOverlay:onTap method, i just pop up a dialog. onTap would be where we add the navigation to where you want to be in the main app.
In previous work i have done with GPS and maps that WAS NOT ANDROID, we would iterate through our data to determine which points were on screen and add them in to the display list. We would start over each time the display was moved so we only drew the markers for the on screen locations. However, Android map overlays work differently. We can put all data points in to the overlay and mapView takes care of deciding what to display as we scroll and zoom. If we don't want to pile a ton of markers into the overlay, i have provided the isClose method. But then we need some logic to determine if we are now looking at a completely different part of the world and clear the old overlay and then update it with points now near the new view point.
I have the GPS being turned on when the app is in the foreground and off when it's in the background. I turn the GPS on in onResume and only set it to read location once a minute and only report if we moved more than 20 meters. Since the only thing i did with the data is in onLocationChanged, i put the data into the log and watch it on the LogCat panel in Eclipse. This is where i would like to talk to the team about how you want to tie this into the main app. There are 2 different ways we might want to use location. We could want to get our current location to create a new SurfRecord for where we are at or we could want to get a location from the map to know to display surf icons in a new area (if we haven't already loaded them all into the overlay.) It looks like the way to do these is to add another overlay, this one a LocationOverlay. It adds a method to display the current location, but that scrolls to our current location. I am rationalizing that we didn't want to display the Santa Clara Innovation Center as a surf location as the reason i didn't just go ahead and add this. With two overlays, there would be multiple ways to get the information about where we tapped as a way to decide if we wanted to create a new SurfRecord at an arbitrary location. We could use onTap and add logic to decide what was going on, or (one i like) would be to use onDoubleTap as a way to signal creating a new location. But i thought this would depend upon how we have the main app working. But none of this last bit is necessary if we provide a separate button as the ui for creating the new surf info spot. Then we can just use the 2 methods mentioned at the top to get the location for that new surfing spot.