Java Code Examples for org.osmdroid.views.overlay.Marker#setPosition()
The following examples show how to use
org.osmdroid.views.overlay.Marker#setPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapUtils.java From AndroidApp with Mozilla Public License 2.0 | 7 votes |
public static void addMarker(Context context, MapView map, Element element) { Marker marker = new Marker(map); marker.setPosition(new GeoPoint(element.lat, element.lon)); marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); map.getOverlays().add(marker); map.invalidate(); marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location)); marker.setTitle(String.valueOf("")); for (Map.Entry<String, String> tag : element.tags.entrySet()) { if (tag.getKey().equals("name")) { marker.setTitle(String.valueOf(tag.getValue())); break; } } if (marker.getTitle().equals("")) marker.setTitle(String.valueOf(element.id)); }
Example 2
Source File: AnimatedMarkerHandler.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.sample_cachemgr, container,false); mMapView = new MapView(getActivity()); ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView); btnCache = root.findViewById(R.id.btnCache); btnCache.setOnClickListener(this); btnCache.setText("Start/Stop Animation"); marker = new Marker(mMapView); marker.setTitle("An animated marker"); marker.setPosition(new GeoPoint(0d,0d)); mMapView.getOverlayManager().add(marker); return root; }
Example 3
Source File: AnimatedMarkerValueAnimator.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.sample_cachemgr, container,false); mMapView = new MapView(getActivity()); ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView); btnCache = root.findViewById(R.id.btnCache); btnCache.setOnClickListener(this); btnCache.setText("Start/Stop Animation"); marker = new Marker(mMapView); marker.setTitle("An animated marker"); marker.setPosition(new GeoPoint(0d,0d)); mMapView.getOverlayManager().add(marker); return root; }
Example 4
Source File: NativeOpenStreetMapController.java From appinventor-extensions with Apache License 2.0 | 6 votes |
private void createNativeMarker(final MapMarker aiMarker, AsyncCallbackPair<Marker> callback) { final Marker osmMarker = new Marker(view); featureOverlays.put(aiMarker, osmMarker); osmMarker.setDraggable(aiMarker.Draggable()); osmMarker.setTitle(aiMarker.Title()); osmMarker.setSnippet(aiMarker.Description()); osmMarker.setPosition(new GeoPoint(aiMarker.Latitude(), aiMarker.Longitude())); osmMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); getMarkerDrawable(aiMarker, new AsyncCallbackFacade<Drawable, Marker>(callback) { @Override public void onFailure(String message) { callback.onFailure(message); } @Override public void onSuccess(Drawable result) { osmMarker.setIcon(result); callback.onSuccess(osmMarker); } }); }
Example 5
Source File: AnimatedMarkerTypeEvaluator.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.sample_cachemgr, container,false); mMapView = new MapView(getActivity()); ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView); btnCache = root.findViewById(R.id.btnCache); btnCache.setOnClickListener(this); btnCache.setText("Start/Stop Animation"); marker = new Marker(mMapView); marker.setTitle("An animated marker"); marker.setPosition(new GeoPoint(0d,0d)); mMapView.getOverlayManager().add(marker); return root; }
Example 6
Source File: AnimatedMarkerTimer.java From osmdroid with Apache License 2.0 | 6 votes |
@Override protected void addOverlays() { super.addOverlays(); mMapView.getController().setCenter(new GeoPoint(0d, 0d)); mMapView.getController().setZoom(5); mMapView.setTilesScaledToDpi(true); mMapView.setMapListener(this); mMapView.getController().setZoom(3); marker = new Marker(mMapView); marker.setPosition(new GeoPoint(45d, -74d)); LatLonGridlineOverlay2 grids = new LatLonGridlineOverlay2(); grids.setBackgroundColor(Color.BLACK); grids.setFontColor(Color.GREEN); grids.setLineColor(Color.GREEN); mMapView.getOverlayManager().add(grids); }
Example 7
Source File: SampleSpeechBalloon.java From osmdroid with Apache License 2.0 | 6 votes |
private void addToDisplay(final POI pPOI) { final Marker marker = new Marker(mMapView); marker.setTitle(pPOI.mTitle); marker.setPosition(pPOI.mGeoPoint); marker.setIcon(mBitmapDrawable); mMapView.getOverlays().add(marker); if (pPOI.mSpeechBalloon) { final SpeechBalloonOverlay speechBalloonOverlay = new SpeechBalloonOverlay(); speechBalloonOverlay.setTitle(pPOI.mTitle); speechBalloonOverlay.setMargin(10); speechBalloonOverlay.setRadius(15); speechBalloonOverlay.setGeoPoint(new GeoPoint(pPOI.mGeoPoint)); speechBalloonOverlay.setOffset(pPOI.mOffsetX, pPOI.mOffsetY); speechBalloonOverlay.setForeground(mForeground); speechBalloonOverlay.setBackground(mBackground); speechBalloonOverlay.setDragForeground(mDragForeground); speechBalloonOverlay.setDragBackground(mDragBackground); mMapView.getOverlays().add(speechBalloonOverlay); } }
Example 8
Source File: OsmMapShapeConverter.java From osmdroid with Apache License 2.0 | 6 votes |
/** * Add a LatLng to the map * * @param map * @param latLng * @param options * @return */ public static Marker addLatLngToMap(MapView map, GeoPoint latLng, MarkerOptions options) { Marker m = new Marker(map); m.setPosition(latLng); if (options!=null) { if (options.getIcon()!=null){ m.setIcon(options.getIcon()); } m.setAlpha(options.getAlpha()); m.setTitle(options.getTitle()); m.setSubDescription(options.getSubdescription()); m.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map)); } map.getOverlayManager().add(m); return m; }
Example 9
Source File: MapViewRealTimeActivity.java From Travel-Mate with MIT License | 6 votes |
/** * Sets marker at given location on map * * @param locationLat latitude * @param locationLong longitude * @param locationName name of location * @param locationIcon icon */ private void showMarker(Double locationLat, Double locationLong, String locationName, Integer locationIcon) { GeoPoint coord = new GeoPoint(locationLat, locationLong); Marker marker = new Marker(mMap); if (ContextCompat.checkSelfPermission(MapViewRealTimeActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { marker.setPosition(coord); marker.setIcon(this.getDrawable(locationIcon)); marker.setTitle(locationName); marker.setOnMarkerClickListener(this); mMap.getOverlays().add(marker); mMap.invalidate(); } }
Example 10
Source File: SampleMilitaryIconsMarker.java From osmdroid with Apache License 2.0 | 6 votes |
private void addIcons(int count) { for (int i = 0; i < count; i++) { double random_lon = MapView.getTileSystem().getRandomLongitude(mRandom.nextDouble()); double random_lat = MapView.getTileSystem().getRandomLatitude(mRandom.nextDouble()); Marker m = new Marker(mMapView); m.setPosition(new GeoPoint(random_lat, random_lon)); final int index = mRandom.nextInt(icons.size()); m.setSnippet("A random point"); m.setSubDescription("location: " + random_lat + "," + random_lon); m.setIcon(icons.get(index)); mMapView.getOverlayManager().add(m); } mMapView.invalidate(); Toast.makeText(getActivity(), count + " icons added! Current size: " + mMapView.getOverlayManager().size(), Toast.LENGTH_SHORT).show(); }
Example 11
Source File: IconPlottingOverlay.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public boolean onLongPress(final MotionEvent e, final MapView mapView) { if (markerIcon != null) { GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null); /* * <b>Note</b></b: when plotting a point off the map, the conversion from * screen coordinates to map coordinates will return values that are invalid from a latitude,longitude * perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you, * the developer using osmdroid to decide on what is right for your application. See * <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a> * for more information and the discussion associated with this. */ //just in case the point is off the map, let's fix the coordinates if (pt.getLongitude() < -180) pt.setLongitude(pt.getLongitude()+360); if (pt.getLongitude() > 180) pt.setLongitude(pt.getLongitude()-360); //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude()) pt.setLatitude(mapView.getTileSystem().getMaxLatitude()); if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude()) pt.setLatitude(mapView.getTileSystem().getMinLatitude()); Marker m = new Marker(mapView); m.setPosition(pt); m.setIcon(markerIcon); m.setImage(markerIcon); m.setTitle("A demo title"); m.setSubDescription("A demo sub description\n" + pt.getLatitude() + "," + pt.getLongitude()); m.setSnippet("a snippet of information"); mapView.getOverlayManager().add(m); mapView.invalidate(); return true; } return false; }
Example 12
Source File: MarkerDrag.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays(){ super.addOverlays(); //0. Using the Marker overlay Marker startMarker = new Marker(mMapView); startMarker.setPosition(new GeoPoint(0.0,0.0)); startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); startMarker.setTitle("Start point"); startMarker.setDraggable(true); startMarker.setOnMarkerDragListener(new OnMarkerDragListenerDrawer()); mMapView.getOverlays().add(startMarker); }
Example 13
Source File: WeathForceActivity.java From osmdroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_starter_mapview); Intent intent = getIntent(); //if (intent) final double lat1 = 25.633; final double long1 = 71.094; //super important. Many tile servers, including open street maps, will BAN applications by user //agent. Do not use the sample application's user agent for your app! Use your own setting, such //as the app id. Configuration.getInstance().setUserAgentValue(getPackageName()); mMapView = findViewById(R.id.mapview); mMapView.setTileSource(TileSourceFactory.MAPNIK); mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mMapView); mCompassOverlay.enableCompass(); mMapView.getOverlays().add(this.mCompassOverlay); addOverlays(); GeoPoint startPoint = new GeoPoint(lat1, long1); IMapController mapController = mMapView.getController(); mapController.setZoom(9); mapController.setCenter(startPoint); Marker startMarker = new Marker(mMapView); startMarker.setPosition(startPoint); startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); mMapView.getOverlays().add(startMarker); mMapView.invalidate(); }
Example 14
Source File: Bug512Marker.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays(){ super.addOverlays(); marker = new Marker(mMapView); marker.setSnippet("Hello world, bug 512 part 1"); marker.setPosition(new GeoPoint(-40d,-74d)); mMapView.getController().setCenter(marker.getPosition()); mMapView.getOverlayManager().add(marker); }
Example 15
Source File: MapUtils.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
public static Marker addMarker(Context context, MapView map, double latitude, double longitude) { if (map == null || context == null) return null; Marker marker = new Marker(map); marker.setPosition(new GeoPoint(latitude, longitude)); marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location)); marker.setInfoWindow(null); map.getOverlays().add(marker); map.invalidate(); return marker; }
Example 16
Source File: MapUtils.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
public static void addMarker(Context context, MapView map, double latitude, double longitude, String markerTitle) { Marker marker = new Marker(map); marker.setPosition(new GeoPoint(latitude, longitude)); marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); map.getOverlays().add(marker); map.invalidate(); marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location)); marker.setTitle(markerTitle); }
Example 17
Source File: MapUtils.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
/** * Add new {@link Marker} to {@link MapView} * * @param context The context to use. Usually your {@link android.app.Application} or {@link android.app.Activity} object. * @param map {@link MapView} to add marker on * @param position Location of the marker */ public static Marker addMarker(Context context, MapView map, GeoPoint position) { Marker marker = new Marker(map); marker.setPosition(position); marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); marker.setIcon(context.getResources().getDrawable(R.drawable.ic_location)); marker.setTitle("Latitude: " + position.getLatitude() + "\n" + "Longitude: " + position.getLongitude()); marker.setPanToView(true); marker.setDraggable(true); map.getOverlays().add(marker); map.invalidate(); return marker; }
Example 18
Source File: NativeOpenStreetMapController.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Override public void updateFeaturePosition(MapMarker aiMarker) { Marker marker = (Marker)featureOverlays.get(aiMarker); if (marker != null) { marker.setAnchor(ANCHOR_HORIZONTAL[aiMarker.AnchorHorizontal()], ANCHOR_VERTICAL[aiMarker.AnchorVertical()]); marker.setPosition(new GeoPoint(aiMarker.Latitude(), aiMarker.Longitude())); view.invalidate(); } }
Example 19
Source File: MapsActivity.java From Finder with GNU General Public License v3.0 | 5 votes |
private void trackRedraw() { Cursor query = db.query("tracking_table", new String[] {"_id", "lat", "lon", "speed", "date"}, "track_id = ?", new String[] {String.valueOf(track_id)}, null, null, "_id ASC"); Cursor last_point = db.rawQuery("SELECT lat, lon, _id FROM tracking_table WHERE _id = (SELECT MAX(_id) FROM tracking_table WHERE track_id = ?)", new String[] {String.valueOf(track_id)}); last_point.moveToFirst(); Double lat = last_point.getDouble(0); Double lon = last_point.getDouble(1); last_point.close(); //zoom to latest point, because BoundBox don't work in OsmDroid library (this is known lib bug) mapController.setCenter(new GeoPoint(lat, lon)); mapController.setZoom(15d); List<GeoPoint> track = new ArrayList<>(); while (query.moveToNext()) { GeoPoint gp = new GeoPoint(query.getDouble(1), query.getDouble(2)); track.add(gp); Marker marker = new Marker(map); marker.setPosition(gp); marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); map.getOverlays().add(marker); marker.setTitle(getString(R.string.date_time, query.getString(4), query.getFloat(3))); } query.close(); line.setPoints(track); GeoPoint center = new GeoPoint(lat, lon); mapController.setCenter(center); }
Example 20
Source File: Plotter.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public void onClick(View v) { switch (v.getId()) { case R.id.radio_milstd2525b: case R.id.radio_milstd2525c: if (((RadioButton) v).isChecked()) { RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525C); } else RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525B); break; case R.id.cancelAddIcon: picker.dismiss(); break; case R.id.addIcon: //from the menu, user entered code String code = symbolCode.getText().toString(); int size = 128; try { size = Integer.parseInt(symbolSize.getText().toString()); } catch (Exception ex) { } String baseCode = SymbolUtilities.getBasicSymbolID(code); SymbolDef def = SymbolDefTable.getInstance().getSymbolDef(baseCode, RendererSettings.getInstance().getSymbologyStandard()); SparseArray<String> attr = new SparseArray<>(); attr.put(MilStdAttributes.PixelSize, size + ""); ImageInfo ii = mir.RenderIcon(code, new SparseArray<String>(), attr); Marker m = new Marker(mMapView); m.setPosition((GeoPoint) mMapView.getMapCenter()); m.setTitle(code); if (def != null) { m.setSubDescription(def.getFullPath()); m.setSnippet(def.getDescription() + "\n" + def.getHierarchy()); } Drawable d = new BitmapDrawable(ii.getImage()); m.setImage(d); m.setIcon(d); int centerX = ii.getCenterPoint().x; //pixel center position //calculate what percentage of the center this value is float realCenterX = (float) centerX / (float) ii.getImage().getWidth(); int centerY = ii.getCenterPoint().y; float realCenterY = (float) centerY / (float) ii.getImage().getHeight(); m.setAnchor(realCenterX, realCenterY); mMapView.getOverlayManager().add(m); mMapView.invalidate(); picker.dismiss(); //TODO store the symbol code and size as an android preference SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit(); edit.putString("MILSTDCODE", code); RendererSettings.getInstance().setDefaultPixelSize(size); edit.putInt("MILSTDSIZE", size); edit.commit(); break; case R.id.enablePanning: enablePanning(); break; case R.id.enablePainting: enablePainting(); break; } }