我有一个Android手机应用程序,即时通讯尝试检查一个特定的LatLng是否在水中,所以即时通讯使用谷歌静态地图API获取位置图像,然后检查图像是蓝色的。Android piccaso回调前加载
IM使用此代码 -
private boolean result;
public boolean IsWater(LatLng position)
{
imageView = (ImageView) this.findViewById(R.id.imageView);
checkText= (TextView) this.findViewById(R.id.checkText);
String lati = Double.toString(position.latitude);
String longi = Double.toString(position.longitude);
String url = "http://maps.googleapis.com/maps/api/staticmap?center="+lati+"," + longi + "&zoom=20&size=1x1&style=element:labels%7Cvisibility:off&style=element:geometry.stroke%7Cvisibility:off";
Picasso.with(MainActivity.this).load(url)
.into(imageView, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(0, 0);
int blueValue = Color.blue(pixel);
if(blueValue>250)
result =true;
}
@Override
public void onError() {
result =false;
}
});
return result;
}
的问题,我想,就是它是不同步的,并且IsWater获得了最后一行和的onSuccess踢之前返回空的结果...
有什么想法?
可能重复[如何使用Picasso加载位图而不使用ImageView?](http://stackoverflow.com/questions/24302431/how-to-load-a-bitmap-with-picasso-without-using -an-imageview) –