Can I find out if a coordinate is inside a city?

前端 未结 3 556
轻奢々
轻奢々 2021-01-02 16:37

Let\'s say I have a LatLng object, is there any way of checking if it represents a possible location within a city? How can I get the limits of a city? I\'m using Google Map

3条回答
  •  Happy的楠姐
    2021-01-02 17:25

    You can use Reverse Geocoding in the Google Geocoder API and check the locality entries and perhaps sublocality entries of results returned. http://code.google.com/apis/maps/documentation/geocoding/#Types

    Note that this probably won't work so well if you have addresses all over the world and want to know "What city is this LatLng in?" On the other hand, it will probably work reasonably well if you want to know "Is this LatLng within Chicago?" There are areas of the world where the data is fairly complete and sensible, and areas where it is incomplete and/or organized in ways you might not expect. (Apparently, the UK uses "county" and "state" very differently from the USA, for example. Even if I'm wrong about that, you get the idea.)

提交回复
热议问题