【问题标题】:Check land or water in google map在谷歌地图中检查土地或水
【发布时间】:2019-01-10 18:55:13
【问题描述】:

我正在生成随机纬度和经度。但无法找到随机纬度和经度的土地或水域。用谷歌API检查,我没有找到,我在谷歌搜索。但我找不到解决方案,请帮助我。我使用了这个来源(https://onwater.io/users/sign_up)网址。它每分钟只提供 15 个请求。我需要 50 lat 和 long 来检查它是陆地还是水。

【问题讨论】:

标签: android google-maps


【解决方案1】:

对于今天最简单的方法是使用 Google Static Map APIStyled Maps:您可以为您的纬度/经度坐标创建一个像素图(大小 = 1x1)的请求,并隐藏除 water 之外的所有功能并将water 颜色设置为例如纯蓝色 (0x0000FF)。类似的东西

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}

然后下载它(就像在Vivek Khandelwalthis答案中):

...

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;
    }
}
...

并测试一个像素的颜色,如thatRaz的答案:

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

如果它是蓝色的 (0x0000FF) - 你的纬度/经度坐标上有水。

注意!您应该设置适当的缩放级别,并记住整个地球的所有缩放级别都没有地图图块。地图上也可能会遗漏一些水/土。所以,这不是 100% 正确的解决方案,但希望它有所帮助。

【讨论】:

    猜你喜欢
    • 2016-09-25
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 2014-02-12
    相关资源
    最近更新 更多