示例#1
0
  private void configureMapView(@NonNull final MapView mapView) {
    mapView.setMultiTouchControls(true);
    mapView.setTilesScaledToDpi(false);

    if (BuildConfig.DEBUG) {
      new MapLoggerListener(mapView);
    }

    final IMapController mapController = mapView.getController();

    if (mMapCenter != null) {
      mapController.setCenter(mMapCenter);
    }

    mapController.setZoom(mZoomLevel);

    final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(getContext(), this);

    // add MapEventsOverlay as primary Map overlay
    mapView.getOverlays().add(0, mapEventsOverlay);
  }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // File file = new File(getFilesDir() + "/osmdroid/tiles/" + "tiles.zip");

    File folder =
        new File(
            Environment.getExternalStorageDirectory().toString() + "/osmdroid/tiles/MapquestOSM");

    if (folder.exists()) {
      Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icono);

      mapView = (MapView) findViewById(R.id.mapview);
      mapView.setTilesScaledToDpi(true);
      mapView.setTilesScaledToDpi(true);
      mapView.setClickable(true);
      mapView.setBuiltInZoomControls(true);
      mapView.setMultiTouchControls(true);
      mapView.setUseDataConnection(false);
      mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
      // mapView.setUseDataConnection(false);

      IMapController mapViewController = mapView.getController();
      mapViewController.setZoom(10);
      mapViewController.setCenter(ROSARIO);
      Marker startMarker = new Marker(mapView);
      LocationManager locationManager =
          (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
      GeoPoint currentLocation = new GeoPoint(location);

      if (location != null) {
        currentLocation = new GeoPoint(location.getLatitude(), location.getLongitude());
      }

      startMarker.setPosition(Fabrica);
      // startMarker.setPosition(new GeoPoint(-32.940380, -60.665102));
      startMarker.setPosition(currentLocation);
      /*int lat= 30;
              int lng=20;
              startMarker.setPosition(new GeoPoint(lat, lng));
      */
      startMarker.setIcon(getDrawable(R.drawable.icono));
      startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
      startMarker.setTitle("Fabrica");
      startMarker.setSnippet("chicos");
      mapView.getOverlays().add(startMarker);
    } else {
      new CopyData().execute();
    }
    /*String FILENAME = "hello_file";
    String string = "hello world!";
    File mydir = this.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;*/
    /*   try {
        FileOutputStream fos = new FileOutputStream(myInternalFile);
        fos.write(myInputText.getText().toString().getBytes());
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }*/
    /*  File wallpaperDirectory = new File("/sdcard/");
    File folder = new File(Environment.getExternalStorageDirectory().toString()+"/sdcard/");
    folder.mkdirs();*/
    /*String filename = "prueba";
            String string = "dsdfsd";
            FileOutputStream outputStream;
            File wallpaperDirectory = new File("/sdcard2/");
            File folder = new File(Environment.getExternalStorageDirectory().toString()+"/sdcard2/");
            folder.mkdirs();
            //Save the path as a string value
            String extStorageDirectory = folder.toString();
    try{
            //File file = new File(extStorageDirectory, "demo.txt");
        File file = new File(extStorageDirectory, "demo.txt");
            FileOutputStream outStream = new FileOutputStream(file);
             outStream.write(string.getBytes());

                outStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }*/

    /* try {
        File wallpaperDirectory = new File("/sdcard2/");
        File folder = new File(Environment.getExternalStorageDirectory().toString()+"/osmdroid/");
        folder.mkdirs();
        AssetManager assetManager = getAssets();
        InputStream inputStream = null;

        InputStream in = assetManager.open("/tiles-example/tiles.zip");

        AssetFileDescriptor descriptor = assetManager.openFd("/tiles-example/tiles.zip");
        File outFile = new File(folder, String.valueOf(descriptor));

        FileOutputStream outStream = new FileOutputStream(String.valueOf(descriptor));
        outStream.write(outStream.getBytes());

    } catch (IOException e) {
        e.printStackTrace();
    }*/

    // Create New file and name it Image2.PNG
    // File file = new File(extStorageDirectory, "Image2.PNG");

    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icono);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setTilesScaledToDpi(true);
    mapView.setTilesScaledToDpi(true);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(true);
    mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(10);
    mapViewController.setCenter(ROSARIO);
    Marker startMarker = new Marker(mapView);
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    GeoPoint currentLocation = new GeoPoint(location);

    if (location != null) {
      currentLocation = new GeoPoint(location.getLatitude(), location.getLongitude());
    }

    // startMarker.setPosition(Fabrica);
    // startMarker.setPosition(new GeoPoint(-32.940380, -60.665102));
    startMarker.setPosition(currentLocation);
    /*int lat= 30;
    int lng=20;
    startMarker.setPosition(new GeoPoint(lat, lng));*/

    startMarker.setIcon(getDrawable(R.drawable.icono));
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    startMarker.setTitle("Fabrica");
    startMarker.setSnippet("chicos");
    mapView.getOverlays().add(startMarker);
    /*  public void setTileSource(final ITileSource aTileSource) {
    mTileProvider.setTileSource(aTileSource);
    float density = getResources().getDisplayMetrics().density;
    TileSystem.setTileSize((int) (aTileSource.getTileSizePixels() * density));
    this.checkZoomButtons();
    this.setZoomLevel(mZoomLevel); // revalidate zoom level
    mapView.postInvalidate();*/
    /*ArrayList<OverlayItem> anotherOverlayItemArray;
    anotherOverlayItemArray = new ArrayList<OverlayItem>();

    anotherOverlayItemArray.add(new OverlayItem("0, 0", "0, 0", new GeoPoint(0, 0)));*/

    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
    mapView.getOverlays().add(0, mapEventsOverlay);
  }