开发者

I need to know the predefined point is in the sea or on the land [duplicate]

This question already has answers here: Verify if a point is Land or Water in Google Maps (20 answers) Closed 5 years ago.

I have a system where users put some coordinates (latitude/longitude), I need to check if specified coordinates are in the sea or not. Is there any service that could give me the answer. Or is i开发者_StackOverflowt possible to do this using google maps.


You can use the Google Maps Geocode API.

If your address is in land, the result_type of the response will be something like "administrative_area". if you are in the sea, the response will be "natural_feature".

Here are two examples:

  • The first is the 0,0 point, in the middle the the Atlantic Ocean: http://maps.google.com/maps/api/geocode/xml?address=0,0&sensor=false
  • The second is located at 20.012065,-6.82251, in the middle of the Saharan desert: http://maps.google.com/maps/api/geocode/xml?address=20.012065,-6.82251&sensor=false

Edit: Some more examples in response to comments:

  • This point is located in the sea claimed by UK, within the 12 miles limit. It shows as "natural_feature": http://maps.google.com/maps/api/geocode/xml?address=50.801541,0.424519&sensor=false
  • This point is located in the Lake Superior, in the Thunder Bay. It shows as "natural_feature": http://maps.google.com/maps/api/geocode/xml?address=48.23565,-86.981506&sensor=false


I have thought about this once before.

I would not use a web service. but I would use a pretty simple image.

I need to know the predefined point is in the sea or on the land [duplicate]

This image is taken from http://www.vectorworldmap.com/vectormaps/vector-world-map-v2.2-blank.jpg

EDIT from a great comment

I like the solution, but I'm not sure that map is totally accurate or equirectangular (which would be the easiest to work with). How about this one? naturalearth.springercarto.com/ne3_data/8192/masks/water_8k.png

//END

  • I would map lat/long over this map for know points so you know your map is correct.
  • For any give point, I would locate the pixel location on this map and figure out the colour (php can do this).
  • If the colour is white, I would say it is sea, black = land.
  • if you dont want lakes, open the map up and color all the lakes black.

If you need super high res maps, I would get a very large map and divide it up in a grid of smaller images that you can load.

If you need to make this system super duper fast. I would can this image pixel for pixel and create a database of this stuff so you can look it up pretty quick. But already this image below actually acts as an excellent database that can be easily checked or changed.

Did you want oceans and lakes?

Curious to know where you are going with this, as I like this problem.

John.


Expanding on John Ballinger, i have successfully used this trick:

  • Get a 1x1 pixel google image static map centered on your coordinates
  • Style map to black (land) and white (water) via Google Maps API styling
  • Find whether the pixel is black or white

In php:

$lat = your latitude
$lon = your longitude
$im = imagecreatefrompng('http://maps.googleapis.com/maps/api/staticmap?center='.$lat.','.$lon.'&zoom=21&format=png&sensor=false&size=1x1&maptype=roadmap&style=feature:administrative|visibility:off&style=feature:landscape|color:0x000000&style=feature:water|color:0xffffff&style=feature:road|visibility:off&style=feature:transit|visibility:off&style=feature:poi|visibility:off');
//get pixel color, put it in an array
$color_index = imagecolorat($im, 0, 0);
$color_tran = imagecolorsforindex($im, $color_index);

//if, for example, red value of the pixel is 0 we are on land
if($color_tran['red']==0){
    //do your thing
    echo "we are on land";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜