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 V3.
Have you tried reverse geocoding?
http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding
You could check the formatted address to see if the city matches what you're looking for. I'm not sure how accurate this will be for your application, but it's an option.
function codeLatLng() {
var geocoder = new google.maps.Geocoder(),
latlng = new google.maps.LatLng(40.730885, -73.997383);
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1]);
console.log(results[1].formatted_address);
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
City limits and other municipalities are constantly re-drawn. There are certain services that exist to help you find them, but I'm not positive that Google keeps a record of city limits inside their data for the Google maps. Here's a discussion in google groups about it. A snippet from that site:
Depending where you are in the world, city limits and other administrative boundaries are CONSTANTLY being changed, and it's even sometimes difficult for local governments to keep their data current because of annexations and other changes. Also, 'city' might be something relative small or the size of Shanghai. Also, different countries can also have sometimes conflicting definitions what administrative unit is the actual definition - a good example is China. Probably your best approach is to get your data from a local government or a data supplier and build your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With