Load Google Static Map with Picasso on Android - android

I'm developing an app with Android Studio, I'd like to create a RecyclerView where I have an ImageView and upload a static image of a determining point on the map.
Like here: https://developers.google.com/maps/documentation/maps-static/intro
I tried to use this method with Picasso (Library that takes an image of a url and loads an ImageView) but nothing happens, with other urls of images on the internet that I used to test it worked and loaded in ImageView but with that nothing appears:
imageMap = findViewById(R.id.imageMap);
String lat = "-12.958811";
String lon = "-38.401606";
String url ="https://maps.googleapis.com/maps/api/staticmap?";
url+="&zoom=14";
url+="&size=330x130";
url+="&maptype=roadmap";
url+="&markers=color:green%7Clabel:G%7C"+lat+", "+lon;
url+="&key=MY_KEY";
Picasso.get().load(url).into(imageMap);
Does anyone know how to do this? With this or another method?
I have tried the methods in other posts reporting this problem but my url is correct in relation to the others.

Make sure you're using the right API key (use the one specifically for Android) and get a more detailed stacktrace by adding a simple success/error callback: Android: Picasso load image failed . how to show error message

You need to enable the billing option in your project. Google change the payment methods and now you need to enable this option in order to use some APIs.

Related

Android Kotlin - picasso refresh / invalidate cached image from URL

This is the code I'm using to show an image:
Picasso.get().load(profileImgUrl).transform(CircleTransform()).into(profileUserImage)
Now I want to refresh it when this image changes on the server
I tried:
Picasso.get().load(profileImgUrl).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).transform(CircleTransform()).into(profileUserImage)
and also
Picasso.with(getContext()).invalidate(profileImgUrl)
As suggested in countless answers but with isn't working any more so I tried
Picasso.get().invalidate(profileImgUrl)
All of this isn't working and I don't want to use the stupid workaround with adding milliseconds or anything to the image URL but just refresh it how it suppose to be possible!

Glide is not working in my project

I am developing an application in which i am using Glide Library to load image from server. But Unfortunately this is not working and i am completely unaware about this and trying to solve this issue since last two days.
this is my code.
Glide.with(this).load(response.getBank_cash_deposit().getData().getAttributes().getAttachment()).into(mSelectedImage);
Try Log your image response. you're getting correct image URL or not.
If the image URL is correct then check whether there is space in your image URL or not.
If the space is exists then replace space in your URL String with %20 with the help of string.replace() function.
String image=response.getBank_cash_deposit().getData().getAttributes().getAttachment();
Log.d("Image",image);
if space exists
then
image.replace(" ","%20");
Also check image url on web.

displaying an image from drive in Android

I'm using Fresco library to display images in my Android app. I'd like to display some images (jpg or png) that I have set with public grants.
When I was doing quick tests, I just took any image from internet to set a URL, but when using the real ones that I need to use, I have the following url https://drive.google.com/uc?export=view&id=<>, but as it is a redirect and, once redirected, new url is not the image itself, Fresco is unable to display it.
I have tried Picasso as an alternative library, but with out any success.
I have also tried the download url for both libraries (https://drive.google.com/uc?export=download&id=<>). But no result.
Anybody knows how could it be possible to get this images? Or the only solution is to download it (using the second url) processing the object received store a bitmap of it and displaying it?
For downloading it, what should i use and how? retrofit?
Thanks in advance.
Fresco supports different network stacks. For example, you can use OkHttp with Fresco, which should follow redirects or modify the default one to allow redirects - or write your own based on them.
Guide for OkHttp: http://frescolib.org/docs/using-other-network-layers.html
Related GitHub issue: https://github.com/facebook/fresco/issues/61
I found a solution for this problem (but could be only applicable if you use Google Cloud or Google Script).
It consists on creating a doGet() service with the following code inside:
var file = DriveApp.getFileById(fileId)
return Utilities.base64Encode(file.getBlob().getBytes());
and use that base64 value in your app. With this format, Fresco can do the magic
It is not an immediate solution, and requires to do somework in other platform that is not your Android app, but it works perfectly.
Are you sure that there is no problems with your URLs?
Picasso works with direct URLs like: https://kudago.com/media/images/place/06/66/06662fda6309ce1ee9116d13bd1c66d5.jpg
Then you can download your image like:
Picasso.with(this)
.load(url)
.noFade()
.placeholder(R.drawable.placeholder_grey) //if you want to use a stub
.into(imageView, new com.squareup.picasso.Callback() {
#Override
public void onSuccess() {
//here you can operate with image after it is downloaded
}
#Override
public void onError() {
}
});
Hope it will help you.

Android reverse image search

In my project i need to include searchs to a API Rest to query with a url that points to a jpg picture and it returns a list of urls with similar pictures.
Google Images performs via web like i am looking for, but the clients for Android that i have found (github projects) they work simply with an input text.
The simplest code would be something as below:
String inputUrlPic = "https://cdn.pixabay.com/photo/2014/03/14/20/13/dog-287420__340.jpg";
String[] returnedUrlPictures = null; //list of returned pictures similars to inputUrlPic
ReverseImageApi reverseImageApi = new ReverseImageApi();//My desired Api object
returnedUrlPictures = reverseImageApi.findSimilarPicturesFromUrl(inputUrlPic); //Ok, it would be an asynctask
So, my question is, exists a API or an Android client API to perform in this way?

Unable to fetch GPlus profile pic. Is the Google Plus Image fetch URL updated?

It's weird, but till yesterday i was able to get the gplus user's image in my app but today it's just not coming. Nothing simply blank. And just appears at some time..
I have been using the urls specified in Getting Google+ profile picture url with user_id but these all seem invalid and gives 404 Error.
https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100
If anybody could help me out why this weird behaviour. The Profile pic appears seldom. But mostly it's blank.
The image URL you were using was never a public API and so there was no guarantee it would continue to work. The recommended practice going forward is to use the people.get API method to get the profile => image => url value instead. That URL could stop working if the user changes their avatar so you might want to fetch the actual image and cache it on your own servers.
I think the Image url has been updated.
Inorder to get that, we can use the PlusClient objects methods:
imageURL = mPlusClient.getCurrentPerson().getImage().getUrl()
{Returns a String - Image Url as String}
imageURL = mPlusClient.getCurrentPerson().getImage()
{Returns an instance of Image object}

Categories

Resources