谷歌地图检查土地或水 [英] Check land or water in google map

查看:143
本文介绍了谷歌地图检查土地或水的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

今天,最简单的方法是使用Google 静态地图API 样式化地图:您可以为您的Lat创建只有一个像素地图(大小= 1x1)的请求除了 water 并将 water 颜色设置为纯蓝色(0x0000FF)。类似的东西



https://maps.googleapis.com/maps/api/staticmap?&center= {YOUR_LAT},{YOUR_LON}&安培;变焦= {YOUR_ZOOM}&安培;大小= 1×1&安培;式=特征:所有|可见度:off& style = feature:water | visibility:on& style = feature:water | color:0x0000FF& key = {YOUR_API_KEY}

然后下载它在 的答案中Vivek Khandelwal ):


  ... 

public static Bitmap getGoogleMapThumbnail(double lati,double longi){
String URL =http://maps.google.com/maps/api/staticmap?center=+ lati +,+ longi +& amp; amp; ;变焦= 15&安培;大小= 200×200&安培;传感器=假;
位图bmp = null;
bmp = getBitmapFromURL(URL);
return bmp;


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


并测试一个像素的颜色,如 的答案。 com / users / 590221 / raz> Raz


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


if它是蓝色(0x0000FF) - 纬度/经度坐标上有水。

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


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.

解决方案

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 coords.

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.

这篇关于谷歌地图检查土地或水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆