/** @see com.brantapps.polaris.api.Mappable#animateCamera(GeoPoint, int) */
 @Override
 public void animateCamera(final GeoPoint geoPoint, final int zoomLevel) {
   // FIXME: Need to run this on the UI thread. @ForActivity qualify the Context & cast using
   // activity graphs.
   mapView.getController().setZoom(zoomLevel);
   mapView
       .getController()
       .setCenter(new org.osmdroid.util.GeoPoint(geoPoint.getLatitude(), geoPoint.getLongitude()));
 }
  private boolean tapZoom(final MotionEvent event) {
    if (zoomIn_.hit(event)) {
      if (zoomIn_.enabled()) mapView_.getController().zoomIn();
      return true;
    } // if ...
    if (zoomOut_.hit(event)) {
      if (zoomOut_.enabled()) mapView_.getController().zoomOut();
      return true;
    } // if ...

    return false;
  } // tapPrevNext
Exemple #3
0
  private void updateMapLocation(GeoPoint geoPoint) {
    Log.d(TAG, "updateMapLocation():  ");
    ItemizedOverlay<OverlayItem> locationOverlay;
    ResourceProxy resourceProxy =
        new DefaultResourceProxyImpl(getActivity().getApplicationContext());

    if (geoPoint != null) {
      ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
      items.add(new OverlayItem("Here", "SampleDescription", geoPoint));

      locationOverlay =
          new ItemizedIconOverlay<OverlayItem>(
              items,
              new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                @Override
                public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                  return true;
                }

                @Override
                public boolean onItemLongPress(final int index, final OverlayItem item) {
                  return false;
                }
              },
              resourceProxy);

      mapView.getOverlays().clear();
      mapView.getOverlays().add(locationOverlay);
      mapView.getController().setCenter(geoPoint);
      mapView.invalidate();
    } else {
      mapView.getOverlays().clear();
      mapView.invalidate();
    }
  }
 public void centerOnUserLocation() {
   GeoPoint p = locationOverlay.getMyLocation();
   if (p == null) {
     p = new GeoPoint(MAP_CENTER_LATITUDE, MAP_CENTER_LONGITUDE);
     Toast.makeText(mContext, "Sorry! Could not determine your location.", Toast.LENGTH_SHORT);
   }
   mapView.getController().animateTo(p);
 }
Exemple #5
0
 /**
  * Animated equivalent to {@link MapController#scrollBy(int, int)}. Scroll by a given amount using
  * the default animation, in pixels.
  *
  * <p><strong>Limitations</strong>: This method internally uses {@link
  * MapController#animateTo(com.google.android.maps.GeoPoint)} which doesn't animate anything if
  * the point is really far (in pixels) from the current point. In this case, nothing will be
  * animated at all.
  *
  * @param mapView The {@link MapView} to scroll
  * @param dx The horizontal scroll amount in pixels.
  * @param dy The vertical scroll amount in pixels.
  */
 public static void smoothScrollBy(MapView mapView, int dx, int dy) {
   final Projection projection = mapView.getProjection();
   final Point tmpPoint = TEMP_POINT;
   projection.toPixels(mapView.getMapCenter(), tmpPoint);
   tmpPoint.offset(dx, dy);
   IGeoPoint geoPoint = projection.fromPixels(tmpPoint.x, tmpPoint.y);
   //        mapView.getController().animateTo(geoPoint);
   mapView.getController().setCenter(geoPoint);
 }
  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);
    }
  }
  /**
   * Populates this bubble with all item info:
   *
   * <ul>
   *   title and description in any case,
   * </ul>
   *
   * <ul>
   *   image and sub-description if any.
   * </ul>
   *
   * and centers the map on the item. <br>
   */
  public void showBubble(ExtendedOverlayItem item, InfoWindow bubble, MapView mapView) {
    Log.d(TAG, "showBubble");
    // offset the bubble to be top-centered on the marker:
    Drawable marker = getMarker(mapView.getZoomLevel());
    int markerWidth = marker.getIntrinsicWidth();
    int markerHeight = marker.getIntrinsicHeight();

    Point markerH = item.getHotspot(HotspotPlace.BOTTOM_CENTER, markerWidth, markerHeight);
    Point bubbleH = item.getHotspot(HotspotPlace.BOTTOM_CENTER, markerWidth, markerHeight);
    bubbleH.offset(-markerH.x, -markerH.y - markerHeight);
    bubble.open(item, bubbleH.x, bubbleH.y);

    mapView.getController().animateTo(item.getPoint());
  }
  @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;
  }
Exemple #9
0
  public GeoTrackOverlay(
      final Context ctx,
      final MapView mapView,
      final ResourceProxy pResourceProxy,
      LoaderManager loaderManager,
      Person person,
      long timeInMs,
      GeotrackLastAddedListener geotrackLastAddedListener) {
    super(pResourceProxy);
    GEOTRACK_LIST_LOADER = R.id.config_id_geotrack_list_loader + (int) person.id + 1000;
    // person.id;
    Log.d(TAG, "#################################");
    Log.d(TAG, "### Create " + person);
    Log.d(TAG, "#################################");
    this.context = ctx;
    this.person = person;
    this.loaderManager = loaderManager;
    this.mapView = mapView;
    this.mMapController = mapView.getController();

    setDateRange(timeInMs);
    // Service
    this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    enableThreadExecutors();
    if (Geocoder.isPresent()) {
      this.geocoder = new Geocoder(context, Locale.getDefault());
    } else {
      this.geocoder = null;
      Log.w(TAG, "The Geocoder is not Present");
    }
    // Listener
    this.geotrackLastAddedListener = geotrackLastAddedListener;
    mStatusReceiver = new StatusReceiver();
    try {
      mStatusReceiverIntentFilter =
          new IntentFilter(
              Intents.ACTION_NEW_GEOTRACK_INSERTED, GeoTrackerProvider.Constants.ITEM_MIME_TYPE);
    } catch (MalformedMimeTypeException e) {
      Log.e(TAG, "Coud not create Intenfilter for mStatusReceiver : " + e.getMessage(), e);
    }

    // Init
    initDirectionPaint(person.color);
    onResume();
  }
Exemple #10
0
  /**
   * Smoothly animates the {@link MapView} so that it centers on the user location. In case, no
   * location is currently available, the error message is displayed to the user via a regular
   * Toast.
   *
   * @param mapView The {@link MapView} to animate
   * @param myLocationOverlay The {@link MyLocationOverlay} whose location will be used to determine
   *     the user location.
   * @param errorMessage The message to display in case no location is available.
   */
  public static void smoothCenterOnUserLocation(
      MapView mapView, MyLocationOverlay myLocationOverlay, String errorMessage) {
    if (myLocationOverlay == null) {
      return;
    }

    final GeoPoint myLocation = myLocationOverlay.getLastFixAsGeoPoint();
    if (myLocation != null) {
      // TODO Cyril: Find a way to stop all animations
      // prior animating to the given location otherwise the call
      // to animateTo is no-op. None of the methods I've tried can
      // stop the fling animation :s
      // getController().stopPanning();
      //            mapView.getController().animateTo(myLocation);
      mapView.getController().setCenter(myLocation);
    } else {
      Toast.makeText(mapView.getContext(), errorMessage, Toast.LENGTH_SHORT).show();
    }
  }
  // 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;
  }
Exemple #12
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);
  }
Exemple #13
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();
  }
  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);
  }
Exemple #16
0
  private void updateLocation(String devId) {
    LocationModel lm = LocationModel.getInstance();
    List<Location> locList = lm.getLocations(devId);
    Location prevLoc = null;
    Location currLoc = locList.get(locList.size() - 1);

    if (locList.size() > 1) {
      prevLoc = locList.get(locList.size() - 2);
      GeoPoint p = new GeoPoint(prevLoc.getLatitude(), prevLoc.getLongitude());
      prevLocationsOverlay.addItem(p, prevLoc.getInfo(), prevLoc.getInfo());
    }

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

    GeoPoint myPoint1 = new GeoPoint(currLoc.getLatitude(), currLoc.getLongitude());
    currLocationOverlay.removeAllItems();
    currLocationOverlay.addItem(myPoint1, currLoc.getInfo(), currLoc.getInfo());

    mapView.getController().setZoom(13);
    mapView.getController().animateTo(myPoint1);
    mapView.invalidate();
  }
  public MxmMyLocationOverlay(
      final Context ctx,
      final MapView mapView,
      final Activity mActivity,
      final ResourceProxy pResourceProxy) {
    super(pResourceProxy);
    mMapView = mapView;
    thisActivity = mActivity;
    sogTxt = (TextView) thisActivity.findViewById(R.id.sog);
    cogTxt = (TextView) thisActivity.findViewById(R.id.cog);
    btnFollow = (Button) thisActivity.findViewById(R.id.btnFollow);
    mLocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
    mSensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
    final WindowManager windowManager =
        (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    mDisplay = windowManager.getDefaultDisplay();

    mMapController = mapView.getController();
    mCirclePaint.setARGB(0, 100, 100, 255);
    mCirclePaint.setAntiAlias(true);

    NULLDIRECTION_ICON = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.circle);
    DIRECTION_ARROW = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ship);

    NULLDIRECTION_ICON_CENTER_X = NULLDIRECTION_ICON.getWidth() / 2 - 0.5f;
    NULLDIRECTION_ICON_CENTER_Y = NULLDIRECTION_ICON.getHeight() / 2 - 0.5f;

    DIRECTION_ARROW_CENTER_X = DIRECTION_ARROW.getWidth() / 2 - 0.5f;
    DIRECTION_ARROW_CENTER_Y = DIRECTION_ARROW.getHeight() / 2 - 0.5f;

    createCompassFramePicture();
    createCompassRosePicture();

    COMPASS_FRAME_CENTER_X = mCompassFrame.getWidth() / 2 - 0.5f;
    COMPASS_FRAME_CENTER_Y = mCompassFrame.getHeight() / 2 - 0.5f;
    COMPASS_ROSE_CENTER_X = mCompassRose.getWidth() / 2 - 0.5f;
    COMPASS_ROSE_CENTER_Y = mCompassRose.getHeight() / 2 - 0.5f;
  }
Exemple #18
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 #20
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();
    }
  }
 /** @see com.brantapps.polaris.api.Mappable#zoomOut() */
 @Override
 public boolean zoomOut() {
   return mapView.getController().zoomOut();
 }
 /** @see com.brantapps.polaris.api.Mappable#setZoom(float) */
 @Override
 public void setZoom(final float aZoomLevel) {
   mapView.getController().setZoom((int) aZoomLevel);
 }
Exemple #23
0
 /** default behaviour when no click listener is set */
 protected boolean onMarkerClickDefault(Marker marker, MapView mapView) {
   marker.showInfoWindow();
   if (marker.mPanToView) mapView.getController().animateTo(marker.getPosition());
   return true;
 }