title: Graphics2D to paint a line on a map
body: <p>I'm trying to paint a path on a map using coordinates. I'm trying to use GeneralPath but it doesn't create a line just bunch of dots where lat/long coordinates are. How do I connect them or is there something else that I can use? Not really familiar with Graphics2D..</p>
  
  <pre><code>region.add(new GeoPosition(47.2971, -122.3822));
  region.add(new GeoPosition(47.2975, -122.3701));
  region.add(new GeoPosition(47.3006, -122.3535));
  region.add(new GeoPosition(47.2899, -122.3356));
  region.add(new GeoPosition(47.2895, -122.3111));
  region.add(new GeoPosition(47.2903, -122.2989));
  region.add(new GeoPosition(47.2929, -122.2921));
  region.add(new GeoPosition(47.2914, -122.2920));
  region.add(new GeoPosition(47.2934, -122.2883));
  
  
  Painter&lt;JXMapViewer&gt; overlay = new Painter&lt;JXMapViewer&gt;() {
      public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
          g = (Graphics2D) g.create();
          //convert from viewport to world bitmap
          Rectangle rect = map.getViewportBounds();
          g.translate(-rect.x, -rect.y);          
          GeneralPath path = new GeneralPath();
          //Polygon poly = new Polygon();
          for(GeoPosition gp : region) {
              //convert geo to world bitmap pixel
              mapViewer.setZoom(60);
              Point2D pt = map.getTileFactory().geoToPixel(gp, map.getZoom());
              //poly.addPoint((int)pt.getX(),(int)pt.getY());
              path.moveTo((int)pt.getX(),(int)pt.getY());
              path.lineTo((int)pt.getX(),(int)pt.getY());                                                                         
          }           
          //do the drawing
          g.setColor(new Color(255,0,0,100));
          g.fill(path);           
          g.setColor(Color.RED);
          g.draw(path);           
          g.dispose();
      }
  </code></pre>