Using Google Maps\' API v3, how can I geocode a city name, and have a map returned with the outline of the result? usually this is a political entity with strict boundaries,
There isn't any API (at present) that provides that data.
Enhancement request
I think you will need Tiger/Line files as referenced in this answer. You can use the data to generate polygons. Use Geocoder.geocode
to search for city names. Here's a promise based function that I use:
function locateAddress(address) {
var deferred = $q.defer();
if(!address) { $q.resolve(null); return; }
var geocoder = new google.maps.Geocoder();
var a = address;
if(_.isObject(a)) {
a = (a.line1 || '') + ' ' + (a.city || '') + ' ' + (a.state || '') + ' ' + (a.zip || '');
}
geocoder.geocode({ 'address' : a}, function(results, status) {
if(status === 'ZERO_RESULTS') {
deferred.resolve(null);
return;
}
var c = results[0].geometry.location;
deferred.resolve({latitude: c.lat(), longitude: c.lng()});
}, function(err) {
deferred.reject(err);
});
return deferred.promise;
}