/** Wrapper for the OpenStreetMap view. */
  public OpenStreetMapWrapper(final Context context) {
    this.context = context;
    this.markerManager = new OpenStreetMapMarkerManager(this);
    this.overlayItemToMarker = Maps.newHashMap();

    // Create a custom tile source
    final ITileSource seamarks =
        new XYTileSource(
            "seamarks",
            null,
            0,
            19,
            256,
            ".png",
            new String[] {"http://tiles.openseamap.org/seamark/"});
    final MapTileProviderBasic tileProvider = new MapTileProviderBasic(context, seamarks);
    final TilesOverlay seamarksOverlay = new TilesOverlay(tileProvider, context);
    seamarksOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
    seamarksOverlay.setUseSafeCanvas(true);

    // Create the mapview with the custom tile provider array
    this.mapView = new MapView(context, 256);
    this.mapView.setMultiTouchControls(true);
    this.mapView.setUseSafeCanvas(false);
    this.mapView.getOverlays().add(seamarksOverlay);

    CloudmadeUtil.retrieveCloudmadeKey(context);
  }
  public Route request(
      final Context ctx,
      final DirectionsLanguage nat,
      final GeoPoint start,
      final List<GeoPoint> vias,
      final GeoPoint end,
      final RoutePreferenceType pRoutePreference,
      final boolean pProvideGeometry,
      final boolean pAvoidTolls,
      final boolean pAvoidHighways,
      final boolean pRequestHandle,
      final ArrayList<AreaOfInterest> pAvoidAreas,
      final boolean pSaveRoute)
      throws MalformedURLException, IOException, SAXException, ORSException {
    final String cloudmadeurl =
        "http://routes.cloudmade.com/"
            + CloudmadeUtil.getCloudmadeKey()
            + "/api/0.3/"
            + CloudmadeRSRequestComposer.create(nat, start, vias, end, pRoutePreference);
    Log.d(OSMConstants.DEBUGTAG, "Cloudmade url " + cloudmadeurl);
    final URL requestURL = new URL(cloudmadeurl);

    final HttpURLConnection acon = (HttpURLConnection) requestURL.openConnection();
    acon.setAllowUserInteraction(false);
    acon.setRequestMethod("GET");
    acon.setRequestProperty("Content-Type", "application/xml");
    acon.setDoOutput(true);
    acon.setDoInput(true);
    acon.setUseCaches(false);

    /* Get a SAXParser from the SAXPArserFactory. */
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp;
    try {
      sp = spf.newSAXParser();
    } catch (final ParserConfigurationException e) {
      throw new SAXException(e);
    }

    /* Get the XMLReader of the SAXParser we created. */
    final XMLReader xr = sp.getXMLReader();
    /* Create a new ContentHandler and apply it to the XML-Reader*/
    final CloudmadeRSParser openLSParser = new CloudmadeRSParser();
    xr.setContentHandler(openLSParser);

    /* Parse the xml-data from our URL. */
    xr.parse(new InputSource(new BufferedInputStream(acon.getInputStream())));

    /* The Handler now provides the parsed data to us. */
    final Route r = openLSParser.getRoute();
    r.finalizeRoute(vias);

    if (pSaveRoute) {
      /* Exception would have been thrown in invalid route. */
      try {
        // Ensure folder exists
        final String traceFolderPath =
            Util.getAndRoadExternalStoragePath() + SDCARD_SAVEDROUTES_PATH;
        new File(traceFolderPath).mkdirs();

        // Create file and ensure that needed folders exist.
        final String filename = traceFolderPath + SDF.format(new Date(System.currentTimeMillis()));
        final File dest = new File(filename + ".route");

        // Write Data
        final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(dest));

        out.writeObject(r);
        StreamUtils.closeStream(out);
      } catch (final Exception e) {
        Log.e(OSMConstants.DEBUGTAG, "File-Writing-Error", e);
      }
    }

    return r;
  }