コード例 #1
0
 /** constructs a Placemark from a Marker, as a KML Point */
 public KmlPlacemark(Marker marker) {
   this(marker.getPosition());
   mName = marker.getTitle();
   mDescription = marker.getSnippet();
   mVisibility = marker.isEnabled();
   // TODO: Style / IconStyle => transparency, hotspot, bearing.
 }
コード例 #2
0
  @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;
  }
コード例 #3
0
 @Override
 protected void onPostExecute(String s) {
   Polyline roadOverlay = RoadManager.buildRoadOverlay(road, context);
   map.getOverlays().add(roadOverlay);
   Drawable nodeIcon = getResources().getDrawable(R.drawable.marker_node);
   for (int i = 0; i < road.mNodes.size(); i++) {
     RoadNode node = road.mNodes.get(i);
     Marker nodeMarker = new Marker(map);
     nodeMarker.setPosition(node.mLocation);
     nodeMarker.setIcon(nodeIcon);
     nodeMarker.setTitle("Step " + i);
     nodeMarker.setSnippet(node.mInstructions);
     nodeMarker.setSubDescription(Road.getLengthDurationText(node.mLength, node.mDuration));
     map.getOverlays().add(nodeMarker);
   }
   map.invalidate();
 }
コード例 #4
0
  @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);
  }
コード例 #5
0
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  public boolean longPressHelper(GeoPoint p) {
    // DO NOTHING FOR NOW:

    // MotionEvent e=null;
    /*  Projection proj = mapView.getProjection();
    //GeoPoint point = (GeoPoint) proj.fromPixels((int) mapView.getX(), (int) mapView.getY());
    proj = mapView.getProjection();

    p = (GeoPoint) proj.fromPixels((int) mapView.getX(), (int) mapView.getY());

    int lat= p.getLatitudeE6();
    int lgn= p.getLongitudeE6();*/

    double lg = p.getLongitude();
    double lt = p.getLatitude();
    // Toast.makeText(this, lat, Toast.LENGTH_SHORT).show();
    Intent i = new Intent(MainActivity.this, FormularioActivity.class);
    String lat2 = (String.valueOf(lg));
    String lgn2 = (String.valueOf(lt));
    i.putExtra("lat", lat2);
    // i.putExtra("lat",lgn2);
    // startActivity(i);
    /*    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(10);
    mapViewController.setCenter(ROSARIO);*/

    Marker GeoMarker = new Marker(mapView);
    GeoMarker.setPosition(new GeoPoint(lt, lg));
    /*int lat= 30;
    int lng=20;
    startMarker.setPosition(new GeoPoint(lat, lng));*/

    GeoMarker.setIcon(getDrawable(R.drawable.icono));
    GeoMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    InfoWindow infoWindow =
        new InfoWindow(R.layout.bubble_layout, mapView) {
          @Override
          public void onOpen(Object arg0) {
            LinearLayout layout = (LinearLayout) mView.findViewById(R.id.bubble_layout);
            Button btnMoreInfo = (Button) mView.findViewById(R.id.button);
            TextView txtTitle = (TextView) mView.findViewById(R.id.TV_title);
            TextView txtDescription = (TextView) mView.findViewById(R.id.bubble_description);
            TextView txtSubdescription = (TextView) mView.findViewById(R.id.bubble_subdescription);

            /* txtTitle.setText("Title of my marker");
             txtDescription.setText("Click here to view details!");
             txtSubdescription.setText("You can also edit the subdescription");
            */ layout.setOnClickListener(
                new View.OnClickListener() {
                  public void onClick(View v) {
                    // Override Marker's onClick behaviour here
                  }
                });
          }

          @Override
          public void onClose() {}
        };

    GeoMarker.setInfoWindow(infoWindow);

    GeoMarker.setTitle("Fabrica");
    GeoMarker.setSnippet("chicos");
    mapView.getOverlays().add(GeoMarker);
    mapView.invalidate();

    // Toast.makeText(this, "LONGGGG Tapped", Toast.LENGTH_SHORT).show();

    return false;
  }
コード例 #6
0
ファイル: Marker.java プロジェクト: kongx73/osmbonuspack
 /** 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;
 }