Exemple #1
0
  // ======================================================================
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setUseSafeCanvas(false);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);

    locationHandler = new LocationHandler();
    ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());

    Drawable marker = getResources().getDrawable(android.R.drawable.presence_offline);
    int markerWidth = marker.getIntrinsicWidth();
    int markerHeight = marker.getIntrinsicHeight();
    marker.setBounds(0, markerHeight, markerWidth, 0);

    Drawable currMarker = getResources().getDrawable(android.R.drawable.presence_online);
    markerWidth = marker.getIntrinsicWidth();
    markerHeight = marker.getIntrinsicHeight();
    currMarker.setBounds(0, markerHeight, markerWidth, 0);

    prevLocationsOverlay = new MyItemizedOverlay(marker, resourceProxy);
    currLocationOverlay = new MyItemizedOverlay(currMarker, resourceProxy);
    mapView.getOverlays().add(prevLocationsOverlay);
    mapView.getOverlays().add(currLocationOverlay);

    DeviceDb devDb = DeviceDb.getInstance();
    devDb.init(getApplicationContext());
  }
Exemple #2
0
 public void initialmap() {
   mapview = (MapView) this.findViewById(R.id.mapview);
   mapview.setTileSource(TileSourceFactory.MAPQUESTOSM);
   mapview.setBuiltInZoomControls(true);
   mapview.setMultiTouchControls(true);
   mcontrol = (MapController) this.mapview.getController();
   mcontrol.setZoom(15);
 }
  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);
    }
  }
  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);
  }
Exemple #5
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();
  }
  // 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;
  }
  @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);
  }
Exemple #8
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "Map: onCreateView()");

    View view = inflater.inflate(R.layout.map_main, container, false);

    map = (MapView) view.findViewById(R.id.mapview);
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);
    // Online-Karten verwenden
    map.setUseDataConnection(true);
    // Zoom-Level einstellen
    MapController controllerMap = (MapController) map.getController();
    controllerMap.setZoom(15);

    Location currentLocation =
        (((MainActivity) getActivity()).getLocationsClass()).getCurrentLocation();

    myGeoPoint = new GeoPoint(currentLocation.getLatitude(), currentLocation.getLongitude());
    controllerMap.setCenter(myGeoPoint);

    return view;
  }
  @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);
  }
Exemple #10
0
  /** Called when the activity is first created. */
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
      ctx = this;
      acti = this;
      setContentView(R.layout.open_street_map);
      /* location manager */
      currentLocation = null;
      try {
        // Log.e("find location","dsfdsfdsf");
        lm = (LocationManager) ctx.getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = lm.getBestProvider(criteria, true);
        ll = new MyLocationListener();
        lm.requestLocationUpdates(provider, 0, 0, ll);
      } catch (Exception e) {
      }
      if (!android.provider.Settings.Secure.getString(
              getContentResolver(), android.provider.Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
          .contains("gps")) {
        showDialog(TURN_ON_GPS);
      }
      check = false;
      // show only one photo into map
      Intent intent = getIntent();
      Bundle extract = intent.getExtras();
      if (extract != null) {
        Log.e("OpenStreetMap", "check : " + check);
        check = true;
        path = extract.getString("image-path");
      }
      myOpenMapView = (MapView) findViewById(R.id.openmapview);
      myOpenMapView.setBuiltInZoomControls(true);
      myOpenMapView.setMultiTouchControls(true);
      myMapController = myOpenMapView.getController();
      myMapController.setZoom(16);
      // if (currentLocation != null) myMapController.animateTo(currentLocation);
      btnS = (ImageButton) findViewById(R.id.btnsw);
      btnS.bringToFront();
      btnS.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              Log.e("OpenStreetMap", "check : " + check);
              if (check == true) {
                acti.finish();
                Intent i = new Intent(acti, GalleryMap.class);
                i.putExtra("image-path", path);
                startActivity(i);

              } else {
                PhimpMe.mTabHost.getTabWidget().getChildAt(1).setVisibility(View.GONE);
                PhimpMe.mTabHost.getTabWidget().getChildAt(2).setVisibility(View.VISIBLE);
                PhimpMe.mTabHost.setCurrentTab(2);
              }
            }
          });

      /*
       * Pin photo
       */
      new Thread() {
        public void run() {

          // show only one photo into map

          if (!path.equals("")) {

            Intent intent = getIntent();
            Bundle extract = intent.getExtras();
            if (extract != null && extract.getString("image-path") != null) {
              String path = extract.getString("image-path");

              File f = new File(path);
              ExifInterface exif_data = null;
              geoDegrees _g = null;
              try {
                exif_data = new ExifInterface(f.getAbsolutePath());
                _g = new geoDegrees(exif_data);
                if (_g.isValid()) {

                  try {

                    String la = _g.getLatitude() + "";
                    String lo = _g.getLongitude() + "";
                    int _latitude = (int) (Float.parseFloat(la) * 1000000);
                    int _longitude = (int) (Float.parseFloat(lo) * 1000000);
                    Log.d(
                        "OpenStreetMap ", "Longtitude :" + _longitude + " Latitude :" + _latitude);
                    if ((_latitude != 0) && (_longitude != 0)) {
                      GeoPoint _gp = new GeoPoint(_latitude, _longitude);
                      ExtendedOverlayItem _item =
                          new ExtendedOverlayItem(f.getName(), "", path, _gp, ctx);

                      anotherOverlayItemArray = new ArrayList<ExtendedOverlayItem>();
                      anotherOverlayItemArray.add(_item);
                      ItemizedOverlayWithBubble<ExtendedOverlayItem> anotherItemizedIconOverlay =
                          new ItemizedOverlayWithBubble<ExtendedOverlayItem>(
                              ctx, anotherOverlayItemArray, myOpenMapView);
                      myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);
                      myMapController.animateTo(_gp);
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              } catch (IOException e) {
                e.printStackTrace();
              } finally {
                exif_data = null;
                _g = null;
              }
            }
          }
          // show all photo in gallery
          else {
            Log.e("Show all", "Openstreetmap");
            String[] projection = {MediaStore.Images.Media.DATA};
            Cursor cursor =
                managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
            int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            for (int i = 0; i < cursor.getCount(); i++) {
              if (cursor.moveToNext()) PhimpMe.filepath.add(cursor.getString(columnIndex));
            }

            int count = PhimpMe.filepath.size();
            Log.d("OpenStreetMap", "number local image :" + count);
            // int num_photos_added = 0;
            if (count > 0) {
              int i;
              for (i = 0; i < PhimpMe.filepath.size(); i++) {
                String imagePath = PhimpMe.filepath.get(i);

                Log.d("OpenStreetMap", "gallery map path photos index :" + i + imagePath);
                File f = new File(imagePath);
                ExifInterface exif_data = null;
                geoDegrees _g = null;
                try {
                  exif_data = new ExifInterface(f.getAbsolutePath());
                  _g = new geoDegrees(exif_data);
                  if (_g.isValid()) {

                    try {

                      String la = _g.getLatitude() + "";
                      String lo = _g.getLongitude() + "";
                      int _latitude = (int) (Float.parseFloat(la) * 1000000);
                      int _longitude = (int) (Float.parseFloat(lo) * 1000000);
                      Log.d(
                          "OpenStreetMap ",
                          "Longtitude :" + _longitude + " Latitude :" + _latitude);
                      if ((_latitude != 0) && (_longitude != 0)) {
                        GeoPoint _gp = new GeoPoint(_latitude, _longitude);
                        ExtendedOverlayItem _item =
                            new ExtendedOverlayItem(f.getName(), "", imagePath, _gp, ctx);

                        anotherOverlayItemArray = new ArrayList<ExtendedOverlayItem>();
                        anotherOverlayItemArray.add(_item);
                        /*ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
                        = new ItemizedIconOverlay<OverlayItem>(
                        		ctx, anotherOverlayItemArray, myOnItemGestureListener);     */
                        ItemizedOverlayWithBubble<ExtendedOverlayItem> anotherItemizedIconOverlay =
                            new ItemizedOverlayWithBubble<ExtendedOverlayItem>(
                                ctx, anotherOverlayItemArray, myOpenMapView);
                        ;
                        myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);

                        PhimpMe.filepath.remove(i);
                        // num_photos_added++;
                      }
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                } catch (IOException e) {
                  e.printStackTrace();
                } finally {
                  exif_data = null;
                  _g = null;
                }
              }
            }
          }
        }
      }.start();
      /*Toast.makeText(OpenStreetMap.this,
      num_photos_added +" photos has been displayed on map",
      Toast.LENGTH_LONG).show();	*/

      // Add Scale Bar
      ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
      myOpenMapView.getOverlays().add(myScaleBarOverlay);

      // Add MyLocationOverlay
      myLocationOverlay = new MyLocationOverlay(this, myOpenMapView);
      myOpenMapView.getOverlays().add(myLocationOverlay);
      myOpenMapView.postInvalidate();

    } catch (UnsupportedOperationException u) {
      AlertDialog.Builder alert_bug = new AlertDialog.Builder(ctx);
      alert_bug.setTitle("Error!");
      alert_bug.setMessage("Sorry! Your device not support this service!");
      alert_bug.show();
    }
  }