I currently don't know if there is an easier way to do this, but you can try the following:
- Get a snapshot from your card.
- Get the average color of the snapshot
- Compare the middle color with the predefined forest color
- If their difference is below your accepted tolerance, then you are in the green area map.
The result may not be accurate if you do not zoom in on the map and the green area is too small. In this case, you can do your calculations only at certain zoom levels.
final int forestR = 214;
final int forestG = 233;
final int forestB = 215;
final int tolerance = 60;
Button button = (Button) findViewById(R.id.check_forest_btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap snapshot) {
int pixelCount = 0;
int redColors = 0;
int greenColors = 0;
int blueColors = 0;
for (int y = 0; y < snapshot.getHeight(); y++) {
for (int x = 0; x < snapshot.getWidth(); x++) {
int c = snapshot.getPixel(x, y);
pixelCount++;
redColors += Color.red(c);
greenColors += Color.green(c);
blueColors += Color.blue(c);
}
}
int red = (redColors / pixelCount);
int green = (greenColors / pixelCount);
int blue = (blueColors / pixelCount);
int difference = Math.abs(red - forestR) + Math.abs(green - forestG) + Math.abs(blue - forestB);
boolean isForest = difference < tolerance;
}
};
map.snapshot(callback);
}
});