The biggest struggle I've had with mapping in PCDB Waypoints is in drawing the grid lines.  The literature here is very skimpy, and in particular it's not easy to work out what pixel co-ordinates to use to draw something on the portion of the map that is currently on display.  But with the help of a few useful posts on Stack Overflow, I've managed to put together a class called  GridOverlay which extends Overlay and works with maps supported by OSMDroid.  OSMDroid is an alternative to the mapping facilities provided by Google Maps, which are limited to use with only maps provided by Google.  (Goodness knows what Google hope to achieve by that limitation.)  OSMDroid facilities aOverlays are usually used to draw markers of various sorts on the Map.  GridOverlay doesn't store any markers, or Points (as PathOverlay does), and doesn't have any onTap methods.  Instead, it contains a few getters and setters, and a draw() method which does all the work.

You can find the java code of GridOverlay here.

The draw() method calculates the grid size, aiming to get a minimum of two latitude lines within the MapView's current display area.  It draws the grid only on the portion of the map on display, and redraws it each time it is called, so applications using this overlay should call their MapView's invalidate() method after every zoom or scroll action.  It puts the grid latitude or longitude on each grid line, with longitudes displayed vertically.  The format in which these are displayed can be varied.  Supported formats are LLD (degrees and fractions, e.g. 52.03365°), LLDM (degrees, minutes and fractions of minutes, e.g. 004°13.255'W) or LLDMS (degrees, minutes, seconds and fractions of seconds, e.g. 52°13' 4.3").

To include grid lines on your MapView (represented here as mMapView), define a GridOverlay and add it the map's overlays, thus:
public void  drawGridLines()
{
        GridOverlay ol = new GridOverlay(
                     Color.GRAY
                      GridOverlay.LLDM,
                      mResourceProxy);

       ol.setStrokeWidth(1.0f);
        mMapView.getOverlays().add(ol);
}

Define a MapListener handler for the MapView, thus:



mMapView.setMapListener(new MapListener()
 {
         @Override
         public boolean  onZoom(ZoomEvent ev) 
          {
                updateMapPosition();
                mMapView.invalidate();

                return false;
         }

        @Override
        public boolean onScroll(ScrollEvent ev) 
        {
                updateMapPosition();
                mMapView.invalidate();

                return false;
        }
 });

(In my implementation, updateMapPosition() records the map's centre point and co-ordinates in the text boxes to the right hand side, as shown in the screen shots in my previous blog.)
 
Again, it's some time since I updated this blog, but the wait is, I hope, worth it.  PCDB Waypoints now has the ability to display a route on a map, with the waypoints indicated by markers and a line joining them.  The zoom level of the map is set to ensure that all points on it are included in the area shown.  Where a Waypoint is defined by reference to one or more nearby Marks (i.e. by the distance and bearing from the mark), then at an appropriate zoom level the marks, too, are shown with bearing lines joining them to the appropriate Waypoints.

And, the piece de resistance, grid lines are shown on the map which move around as the map is scrolled, and the grid spacing changes as the map is zoomed.

Here are some screen shots.  The map used is the Open Steet Mapping (OSM) default.  This covers the entire world, but at varying levels of detail, and there are indications that in some areas the coastline (at least) is not properly mapped.  But it's certainly enough to get this project going.
Picture
This shows a popular cruising route in North Wales, from Abersoch to the anchorage at Pilot's Cove behind Llanddwynn Island, just outside Caernarvon bar.

Picture
After zooming the map in a few times, and touching the icon representing the Waypoint just south of Llanddwynn Island, an InfoWindow pops up showing the details of this Waypoint and the two Marks that define its position.  One is a South Cardinal mark at 308.5 degrees, and the other the Llanddwynn Island lighthouse immediately North of the Waypoint.

 
It's been some while since I last added to this blog.  Most of that time has been devoted to my latest project: making PCDB Waypoints display a map over which it can overlay marks, waypoints, or collections of waypoints joined by a route.  It hasn't been easy!

Stage 1 was to get it to display a map - any map.  The eventual intention is to display chart-type data, but most of the mapa data available today is streat maps - either Google's or someone else's.  The Google mapping apps in Android can only be used with Google maps.  I don't want to be restricted in this way, so I've been looking at alternatives.  One is the Open Street Mapping (OSM) initiative, which provides a free-to-use street map of much of the world, and a set of Android APIs to enable an app to access these.  I've now got to the point where, starting from the Waypoints screen, I can call up the OSM map, and show the Waypoint's icon (starboard hand mark, fairway buoy, etc), suitably scaled and positioned at the correct point on the map.  I can then scroll the map and zoom it in and out.

The next stage is to overaly a sequence of Waypoints, find the geographic centre of them and position the map there, the set the zoom level so that the entire route is included on the map pane. That'll keep me busy for a while yet.