Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
738 views
in Technique[技术] by (71.8m points)

android - Check land or water in google map

I am generating random latitude and longitude. But unable to find land or water for random lat and longitude. Checked with google API, I am not finding and I searched in google. But I cannot find solution, please help me. I used this source (https://onwater.io/users/sign_up )url. It gives only 15 request per minute. I need 50 lat and long to check whether it is land or water.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For today easiest way to do this is to use Google Static Map API and Styled Maps: you can create request for just one pixel map (size=1x1) for your Lat/Lon coords with hidden all features except water and set water color to e.g. pure blue (0x0000FF). Something like that

https://maps.googleapis.com/maps/api/staticmap?&center={YOUR_LAT},{YOUR_LON}&zoom={YOUR_ZOOM}&size=1x1&style=feature:all|visibility:off&style=feature:water|visibility:on&style=feature:water|color:0x0000FF&key={YOUR_API_KEY}

Then download it (like in this answer of Vivek Khandelwal):

...

public static Bitmap getGoogleMapThumbnail(double lati, double longi) {
    String URL = "http://maps.google.com/maps/api/staticmap?center=" + lati + "," + longi + "&zoom=15&size=200x200&sensor=false";
    Bitmap bmp = null;
    bmp = getBitmapFromURL(URL);
    return bmp;
}

public static Bitmap getBitmapFromURL(String src) {
    try {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    }
    catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
...

and test color of one pixel like in that answer of Raz:

...
int pixel = bitmap.getPixel(x,y);
if (pixel == Color.BLUE) {
   // water!
}
...

if it blue (0x0000FF) - there is water on your Lat/Lon coordinates.

NB! You should set appropriate zoom level and remember that is no map tiles for all zoom levels for entire Earth. Also some water/earth can be missed on map. So, that is not 100% right solution, but hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...