@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_osm_map, container, false);
    map = (MapView) layout.findViewById(R.id.osmmap);
    map.setTileSource(TileSourceFactory.MAPNIK);
    // map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    // Default location and zoom level
    IMapController mapController = map.getController();
    mapController.setZoom(12);
    GeoPoint startPoint = new GeoPoint(37.4333, 127.1500);
    mapController.setCenter(startPoint);
    // MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(getActivity(), new
    // GpsMyLocationProvider(getActivity()),map);
    // map.getOverlays().add(mLocationOverlay);

    Marker startMarker = new Marker(map);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(startMarker);

    RoadManager roadManager = new OSRMRoadManager(getActivity());
    waypoints = new ArrayList<GeoPoint>();
    waypoints.add(startPoint);
    GeoPoint endPoint = new GeoPoint(37.4314, 127.1297);
    waypoints.add(endPoint);

    Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    myLocationOverlay = new DirectedLocationOverlay(getActivity());
    map.getOverlays().add(myLocationOverlay);
    myLocationOverlay.setLocation(new GeoPoint(location));
    map.invalidate();

    handler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            GeoPoint geo = (GeoPoint) msg.obj;
            map.getController().animateTo(geo);
            map.invalidate();
          }
        };

    return layout;
  }
  private void setupMapView(final IGeoPoint oldCenter, final int oldZoom) {
    // view
    final RelativeLayout rlView = (RelativeLayout) this.findViewById(R.id.map_rl);

    // tryEvil();

    // possibly choose goog maps here
    mapView = new MapView(this, 256);

    if (mapView instanceof View) {
      ViewGroup.LayoutParams params =
          new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
      ((View) mapView).setLayoutParams(params);
    }

    if (mapView instanceof MapView) {
      final MapView osmMapView = (MapView) mapView;
      rlView.addView(osmMapView);
      osmMapView.setBuiltInZoomControls(true);
      osmMapView.setMultiTouchControls(true);

      // my location overlay
      myLocationOverlay = new MyLocationOverlay(getApplicationContext(), osmMapView);
      myLocationOverlay.setLocationUpdateMinTime(ListActivity.LOCATION_UPDATE_INTERVAL);
      myLocationOverlay.setDrawAccuracyEnabled(false);
      osmMapView.getOverlays().add(myLocationOverlay);

      final OpenStreetMapViewWrapper overlay = new OpenStreetMapViewWrapper(this);
      osmMapView.getOverlays().add(overlay);
    }

    // controller
    mapControl = mapView.getController();
    final IGeoPoint centerPoint = getCenter(this, oldCenter, previousLocation);
    int zoom = DEFAULT_ZOOM;
    if (oldZoom >= 0) {
      zoom = oldZoom;
    } else {
      final SharedPreferences prefs = getSharedPreferences(ListActivity.SHARED_PREFS, 0);
      zoom = prefs.getInt(ListActivity.PREF_PREV_ZOOM, zoom);
    }
    mapControl.setCenter(centerPoint);
    mapControl.setZoom(zoom);
    mapControl.setCenter(centerPoint);

    ListActivity.info("done setupMapView. zoom: " + zoom);
  }
Beispiel #3
0
  private void config() {
    mMap.setTileSource(TileSourceFactory.MAPQUESTOSM);
    mMap.setMultiTouchControls(true);
    mMap.setBuiltInZoomControls(true);

    mController = mMap.getController();
    mController.setZoom(18);

    mTreasureMapTileSource =
        new XYTileSource(
            "mbtiles",
            ResourceProxy.string.offline_mode,
            1,
            20,
            256,
            ".png",
            "http://appquest.hsr.ch/hsr.mbtiles");

    try {
      setOfflineMap("hsr.mbtiles");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    ResourceProxy resourceProxy = new DefaultResourceProxyImpl(mContext);
    Drawable drawableMarker = mContext.getResources().getDrawable(R.drawable.marker);
    int markerWidth = drawableMarker.getIntrinsicWidth();
    int markerHeight = drawableMarker.getIntrinsicHeight();
    drawableMarker.setBounds(0, markerHeight, markerWidth, 0);

    mMarkerOverlay = new MarkerOverlay(drawableMarker, resourceProxy);

    mMap.getOverlays().add(mMarkerOverlay);

    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.commit();

    List<GeoPoint> points = new ArrayList<GeoPoint>();

    try {
      String mapPointsString = sharedPreferences.getString(MAP_POINTS, "");

      JSONObject mapPointsJson = new JSONObject(mapPointsString);
      JSONArray array = mapPointsJson.getJSONArray("points");

      for (int i = 0; i < array.length(); i++) {
        JSONObject mapPoint = array.getJSONObject(i);
        points.add(new GeoPoint(mapPoint.getDouble("lat"), mapPoint.getDouble("lon")));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    for (GeoPoint point : points) {
      addMarker(point);
    }
  }
Beispiel #4
0
  @Override
  public void onStart() {
    super.onStart();
    Log.d(TAG, "onStart():  ");

    mapView = (MapView) getView().findViewById(R.id.mapView);

    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(true);
    mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(15);
    mapViewController.setCenter(new GeoPoint(54.7866382, 9.4350427));

    onUpDate();
  }
Beispiel #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    MapView map = (MapView) findViewById(R.id.activityGame_MapView_map);
    map.setTileSource(TileSourceFactory.MAPNIK);
    //        map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    IMapController mapController = map.getController();
    mapController.setZoom(20);
    mapController.setCenter(new GeoPoint(54.318684, 48.403570));

    RotationGestureOverlay rotationGestureOverlay = new RotationGestureOverlay(this, map);
    rotationGestureOverlay.setEnabled(true);
    map.setMultiTouchControls(true);
    map.getOverlays().add(rotationGestureOverlay);
  }
  // You should not need to touch this method
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mapView == null) {
      mapView = new MapView(getActivity(), null);

      mapView.setTileSource(TileSourceFactory.MAPNIK);
      mapView.setClickable(true);
      mapView.setBuiltInZoomControls(true);
      mapView.setMultiTouchControls(true);

      mapController = mapView.getController();
      mapController.setZoom(mapView.getMaxZoomLevel() - 2);
      mapController.setCenter(UBC_MARTHA_PIPER_FOUNTAIN);
    }

    return mapView;
  }
  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);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_osm);
    MyLocationNewOverlay mLocationOverlay;

    MapView map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);

    IMapController mapController = map.getController();
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    mapController.setZoom(18);
    GeoPoint startPoint = new GeoPoint(41.10867, 16.87886);
    mapController.setCenter(startPoint);

    mLocationOverlay =
        new MyLocationNewOverlay(
            getApplicationContext(), new GpsMyLocationProvider(getApplicationContext()), map);
    map.getOverlays().add(mLocationOverlay);
  }
  /* Handles item selections */
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
      case MENU_EXIT:
        {
          MainActivity.finishListActivity(this);
          finish();
          return true;
        }
      case MENU_ZOOM_IN:
        {
          int zoom = mapView.getZoomLevel();
          zoom++;
          mapControl.setZoom(zoom);
          return true;
        }
      case MENU_ZOOM_OUT:
        {
          int zoom = mapView.getZoomLevel();
          zoom--;
          mapControl.setZoom(zoom);
          return true;
        }
      case MENU_TOGGLE_LOCK:
        {
          state.locked = !state.locked;
          String name =
              state.locked
                  ? getString(R.string.menu_turn_off_lockon)
                  : getString(R.string.menu_turn_on_lockon);
          item.setTitle(name);
          return true;
        }
      case MENU_TOGGLE_NEWDB:
        {
          final SharedPreferences prefs = this.getSharedPreferences(ListActivity.SHARED_PREFS, 0);
          final boolean showNewDBOnly = !prefs.getBoolean(ListActivity.PREF_MAP_ONLY_NEWDB, false);
          Editor edit = prefs.edit();
          edit.putBoolean(ListActivity.PREF_MAP_ONLY_NEWDB, showNewDBOnly);
          edit.commit();

          String name =
              showNewDBOnly ? getString(R.string.menu_show_old) : getString(R.string.menu_show_new);
          item.setTitle(name);
          return true;
        }
      case MENU_LABEL:
        {
          final SharedPreferences prefs = this.getSharedPreferences(ListActivity.SHARED_PREFS, 0);
          final boolean showLabel = !prefs.getBoolean(ListActivity.PREF_MAP_LABEL, true);
          Editor edit = prefs.edit();
          edit.putBoolean(ListActivity.PREF_MAP_LABEL, showLabel);
          edit.commit();

          String name =
              showLabel ? getString(R.string.menu_labels_off) : getString(R.string.menu_labels_on);
          item.setTitle(name);
          return true;
        }
      case MENU_FILTER:
        {
          showDialog(SSID_FILTER);
          return true;
        }
    }
    return false;
  }
Beispiel #10
0
 public void setCenter(GeoPoint point) {
   mController.setCenter(point);
 }
Beispiel #11
0
 public void setZoom(int zoom) {
   mController.setZoom(zoom);
 }
  @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);
  }