Find County name for a Lat/Long

后端 未结 5 1791
暖寄归人
暖寄归人 2021-02-05 08:00

I\'m trying to find a webservice that will allow me to get a County name (not Country) for a specific Lat/Long. I would be performing the lookup within a server application (li

相关标签:
5条回答
  • 2021-02-05 08:22

    Another option:

    • Download the cities database from http://download.geonames.org/export/dump/
    • Add each city as a lat/long -> Country mapping to a spatial index such as an R-Tree (some DBs also have the functionality)
    • Use nearest-neighbour search to find the country corresponding to the closest human settlement for any given point

    Advantages:

    • Does not depend on aa external server to be available
    • Much faster (easily does thousands of lookups per second)

    Disadvantages:

    • May give wrong answers close to borders, especially in sparsely populated areas
    0 讨论(0)
  • 2021-02-05 08:33

    Just for completeness, I found another API to get this data that is quite simple, so I thought I'd share.

    https://geo.fcc.gov/api/census/

    The FCC provides an Block API for exactly this problem and it uses census data to perform the look up.

    Their usage limit policy is (From developer@fcc.gov)

    We do not have any usage limits for the block conversion API, but we do ask that you try to spread out your requests over time if you can.

    0 讨论(0)
  • 2021-02-05 08:33

    You may want to have look at Tiger data and see if it has polygons containing the county name in an attribute. If it does the Java Geotools API lets you work with this data. You will be performing point in polygon queries for the county polygons followed by a feature attribute look-up.

    0 讨论(0)
  • 2021-02-05 08:34

    Maybe this is a great solution.It is in a json format.I always use this in my projects.

    http://maps.google.com/maps/geo?ll=10.345561,123.896932

    And simply extract the information using php.

    $x = file_get_contents("http://maps.google.com/maps/geo?ll=10.345561,123.896932");
    
    $j_decodex = json_decode($x);
    
    print_r($j_decodex);
    
    0 讨论(0)
  • 2021-02-05 08:42

    Google does populate the county for your example,

    http://maps.googleapis.com/maps/api/geocode/json?latlng=39.76144296429947,-104.8011589050293&sensor=false

    In the response, look under the key address_components which contains this object representing "Adams" county,

    {
        long_name: "Adams"
        short_name: "Adams"
        -types: [
            "administrative_area_level_2"
            "political"
        ]
    }
    

    Here's from the Geocoding API's docs,

    administrative_area_level_2 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.

    0 讨论(0)
提交回复
热议问题