Verify if a point is Land or Water in Google Maps

后端 未结 18 1682
不知归路
不知归路 2020-11-22 17:16

..and then Google-maps \"divide the waters from the waters\"

Well, not in the biblical sense but..

I would like to know what options I have in order to verif

18条回答
  •  失恋的感觉
    2020-11-22 17:53

    Here is a simple solution

    Because Google does not provide reliable results with regards to coordinates that lay on either ocean or inland bodies of water you need to use another backup service, such as Yandex, to help provide that critical information when it is missing. You most likely would not want to use Yandex as your primary geocoder because Google is far superior in the reliability and completeness of the worlds data, however Yandex can be very useful for the purpose of retrieving data when it relates to coordinates over bodies of water, so use both.


    Yandex Documentation: https://api.yandex.com.tr/maps/doc/geocoder/desc/concepts/input_params.xml


    The steps to retrieve Ocean name:

    1.) Use Google first to reverse geocode the coordinate.

    2.) If Google returns zero results, it is 99% likely the coordinate lies over an ocean. Now make a secondary reverse geocoding request with the same coordinates to Yandex. Yandex will return a JSON response with for the exact coordinates, within this response will be two "key":"value" pairs of importance

    ["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["kind"]
    
    and
    
    ["GeoObject"]["name"]
    

    Check the kind key, if it == "hydro" you know you are over a body of water, and because Google returned zero results it is 99.99% likely this body of water is an ocean. The name of the ocean will be the above "name" key.

    Here is an example of how I use this strategy written in Ruby

    if result.data["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["kind"] == "hydro"
         ocean = result.data["GeoObject"]["name"] 
    end
    

    The steps to retrieve an Inland Body of Water name:

    For this example assume our coordinate lies in a lake somewhere:

    1.) Use Google first to reverse geocode the coordinate.

    2.) Google will most likely return a result that is a prominent default address on land nearby. In this result it supplies the coordinates of the address it returned, this coordinate will not match the one you provided. Measure the distance between the coordinate you supplied and the one returned with the result, if it is significantly different (for example 100 yards) then perform a secondary backup request with Yandex and check to see the value of the "kind" key, if it is "hydro" then you know the coordinate lies on water. Because Google returned a result as opposed to the example above, it is 99.99% likely this is an inland body of water so now you can get the name. If "kind" does not == "hydro" then use the Google geocoded object.

    ["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["kind"]
    
    and
    
    ["GeoObject"]["name"]
    

    Here is the same code written in Ruby to get inland_body_of_water

    if result.data["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["kind"] == "hydro"
         inland_body_of_water = result.data["GeoObject"]["name"] 
    end
    

    A note about Licensing: As far as I know Google does not allow you to use their data to display on any other maps other than those Google offers. Yandex however has very flexible licensing, and you can use their data to be displayed on Google maps.

    Also Yandex has a a high rate limit of 50,000 request / day free of charge, and with no required API key.

提交回复
热议问题