I am using OpenStreetMap, I am able to load custom icons (multiple) from drawable using the following code:
startMarker = new Marker(map);
startMarker.setPosition(new GeoPoint(latitude,longitude));
startMarker.setAnchor(Marker.ANCHOR_CENTER, 1.0f);
startMarker.setTitle((intMarkerID+"").trim());
startMarker.setIcon(getResources().getDrawable(R.drawable.loading));
map.getOverlays().add(startMarker);
I would like to use Picasso or Glide to load marker icons from URL, I already have the URLs in a string format from an array, I just need to apply these strings url_abs_fileName ("Image URLs") as a marker icon for OpenStreetMap (Not Goolge Maps), how can I achieve that?
I need to set OSM icons to something like this (example):
if (url_abs_fileName != null) {
Picasso.with(this)
.load(url_abs_fileName)
.placeholder(R.drawable.loading)
.into((Target) startMarker);
}
Related
I showed a photo on the map using the osmdroid and first methods.
Now I want to read a jpeg format picture from the device memory and show it as a bitmap on the map. The code does not give an error. But the photo is not displayed. please guide me. The following are the first and second method codes.
/// first method
GroundOverlay myGroundOverlay = new GroundOverlay();
myGroundOverlay.setPosition(overlayCenterPoint);
Drawable d = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_imageonmap_test2, null);
myGroundOverlay.setImage(d.mutate());
//myGroundOverlay.setImageBitmap(bitmap);
myGroundOverlay.setDimensions(2000000.0f);
myGroundOverlay.setTransparency(0.25f);
myGroundOverlay.setBearing(0);
mMapView.getOverlays().add(myGroundOverlay);
mMapView.invalidate();
////// second method
Bitmap src = BitmapFactory.decodeFile("/sdcard/osmdroid/20190722033213_1440103389.jpg");
Bitmap bitmap2 = src.copy(Bitmap.Config.ARGB_8888, true);
GroundOverlay myGroundOverlay2 = new GroundOverlay();
myGroundOverlay2.setPosition(overlayCenterPoint);
//myGroundOverlay2.setImageBitmap(src);
myGroundOverlay2.setImageBitmap(bitmap2);
//myGroundOverlay2.setDimensions(2000.0f);
//myGroundOverlay2.setTransparency(0.25f);
myGroundOverlay2.setBearing(0);
mMapView.getOverlays().add(myGroundOverlay2);
mMapView.invalidate();
I assume you are using OSMBonusPack GroundOverlay.
Your code in method 1 seems correct (even if dimension seems huge).
In method 2, setDimensions is missing.
Did you try the OSMBonusPack tutorial "as is" (same position/dimension, same bitmap from resources)?
Also, try: "setBearing(0.0f);" (I'm not confident about implicit cast from int to float)
I am using the Android.gms.maps class to create a custom renderer google map in my Xamarin Forms app, for android phones. I am looking to add an image to my map using GroundOverlayOptions
GroundOverlayOptions newarkMap = new GroundOverlayOptions()
.InvokeImage(BitmapDescriptorFactory.FromResource(/*My image?*/))
.position(e.Point, 8600f, 6500f);
map.AddGroundOverlay(newarkMap);
I need the images resource ID in the commented section of my code. How do I find out an images' resource ID? Is there an alternative way to do it?
Using BitmapDescriptorFactory you have multiple options available to how you obtain the BitmapDescriptor
FromResource
FromAsset
FromPath
FromBitmap
Couple of examples:
To use the FromResource, the image must be within your Resource tree, assumably within the Drawable subfolder, Xamarin will generate an id descriptor for you in the form of Resource.Drawable.XXXXX and that will be an integer constant:
var overlayOption = new GroundOverlayOptions()
.InvokeImage(BitmapDescriptorFactory.FromResource(Resource.Drawable.overlayface2))
.Position(e.Point, 5000f, 5000f);
FromAsset loads the image from the "Assets" subfolder:
var overlayOption = new GroundOverlayOptions()
.InvokeImage(BitmapDescriptorFactory.FromAsset("OverlayFace.png"))
.Position(e.Point, 5000f, 5000f);
FromPath loads the image from an arbitrary path, so you could load an image you downloaded and stored in the app's cache directory, or an image stored on an sdcard, etc...
var overlayOption3 = new GroundOverlayOptions()
.InvokeImage(BitmapDescriptorFactory.FromPath("/mnt/sdcard/Download/OverlayFace.png"))
.Position(e.Point, 5000f, 5000f);
Note: The largest problem people run into is not setting the size of the image correctly, it is in kilometers. not pixels, not miles, etc...
Note: Also for speed, keep your image sizes in the power of 2, otherwise the the map library will have to transform it into a power of 2 image everytime it loads the overlay (memory and performance hit)
My drive url is -
https://drive.google.com/file/d/0B3DFHb2-MdGYa2NMUkVtVkZ1V1k/view?usp=sharing
I want to show it in android imageview using glide. I have tried many ways to show it.
Following is my code to show -
Glide.with(getActivity()).load(readExcelFeed.getImage().toString()).into(ivQueImage);
Please let me know what is the issue in it.
Steps for loads image from Google drive into ImageView by Glide Library
Step 1 : In your Drive which image you want to display on ImageView. You need to get shareable link from the three dots from the google drive. like this "https://drive.google.com/open?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9"
Step 2: Then the base url for display the image. link is
public static String BASE_URL = "https://drive.google.com/uc?id=";
Step 3 : In the Step 1 you see the id of the image then add this id in the base URL. Like this type
"https://drive.google.com/uc?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9"
Step 4 : Use Glide library for display the image on ImageView Like this:
Glide.with(mContext)
.load("https://drive.google.com/uc?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9")
.into(holder.user_image);
Now you can see your image on your ImageView.
Unless I'm missing something, you want to show just that single image using Glide. Just right click on it, select "Copy image address", then use that as your url String for Glide.
String url = "https://lh3.googleusercontent.com/s6-0yxPhDS4Os7SYbP66RCNp-mDwuKr72mLJx9ekuTWYFPgXahCvj-oVatwXELyVfyZzD80YTaiYde4=w1278-h954-rw";
Glide.with(getActivity()).load(url).into(ivQueImage);
For request image source you must use executeMediaAndDownloadTo()
service.files().get(fileId).executeMediaAndDownloadTo(outputStream);
Then you can get byte[] from output stream
byte[] data = outputStream.toByteArray();
and insert it to Glid
RequestOptions options = new RequestOptions();
options.skipMemoryCache(true);
options.diskCacheStrategy(DiskCacheStrategy.NONE);
Glide
.with(this)
.load(data)
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView);
I am figuring out the way to load the mbtiles from mapbox using nutiteq SDK. I know how to load the mbtiles offline using this code
// 1. Create tile data source from mbtiles file
MBTilesTileDataSource tileDataSource = new MBTilesTileDataSource("/sdcard/estonia_ntvt.mbtiles");
// 2. Load vector tile styleset
UnsignedCharVector styleBytes = AssetUtils.loadBytes("osmbright.zip");
MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
// 3. Create vector tile decoder using the styleset
VectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);
// 4. Create vector tile layer, using previously created data source and decoder
TileLayer vectorTileLayer = new VectorTileLayer(tileDataSource, vectorTileDecoder);
// 5. Add vector tile layer
mapView.getLayers().add(vectorTileLayer);
Is there a way to load it directly from mapbox mbtiles url using Nutiteq SDK?
What do you mean by "mapbox mbtiles url", can you give an example? By mbtiles you mean offline packages?
I can think of following MapBox URLs:
a. For MapBox as online raster source see https://developer.nutiteq.com/guides/raster-tile-sources
b. For MapBox as online vector source you need to define also styling, and it needs a bit more coding:
// load style file from assets. Nutiteq style is quite well compatible with MapBox Streets,
// even though NT vector tiles are a bit different
UnsignedCharVector styleBytes = AssetUtils.loadBytes("nutibright-v2.zip");
if (styleBytes != null){
// Create style set
MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
MBVectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);
// Create tile data source and layer for vector tiles
TileDataSource vectorTileDataSource = new HTTPTileDataSource(0, 14, "http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v5/{zoom}/{x}/{y}.vector.pbf?access_token=pk...YOUR-MAPBOX-KEY");
VectorTileLayer baseLayer = new VectorTileLayer(vectorTileDataSource, vectorTileDecoder);
// add layer to map
mapView.getLayers().add(baseLayer);
}
I have included a StreetViewPanoramaFragment in my app, but I also want to show a preview of the streetview as seen in the google maps app.
How can I achieve this?
You can load the street view image by using the Google Street View Image API.
You can specify location and image size etc in the image request URL.
private static String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=90&heading=235&pitch=10";
For requesting image, You can use Square's Picasso library:
Picasso.with(this).load(imageURL).into(imageView);
Or use Google's Volley library:
// Get the ImageLoader through your singleton class.
mImageLoader = MySingleton.getInstance(this).getImageLoader();
mImageLoader.get(imageURL, ImageLoader.getImageListener(mImageView,
R.drawable.def_image, R.drawable.err_image));
Or use bitmap with stream:
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
imageView.setImageBitmap(bitmap);
You can also check out this answer about how to get street view image with XML.