I have a MongoDB database of markers with lat/long and I need another database (or other solution) containing cities, or area level boundaries. If in Geojson polygons it would have been optimal.
I have a field named city (e.g. 'city' : 'New York'
) but I want to narrow down to a city's area/neighborhood level e.g. "Soho". The idea to solve the problem this way is based on Google's new maps. If we type area or zip code we see the red-dotted polygon of that area.
I saw Maxmind's database but it does not have boundaries per city.
My best solution so far is to use Google's Geocoding API which returns a box's bounds:
e.g. for: http://maps.googleapis.com/maps/api/geocode/json?address=soho&sensor=false
Result:
{
"results" : [
{
"address_components" : [
{
"long_name" : "SoHo",
"short_name" : "SoHo",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Manhattan",
"short_name" : "Manhattan",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "SoHo, New York, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.7283442,
"lng" : -73.9953929
},
"southwest" : {
"lat" : 40.7184446,
"lng" : -74.0054619
}
},
"location" : {
"lat" : 40.723384,
"lng" : -74.001704
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.7283442,
"lng" : -73.9953929
},
"southwest" : {
"lat" : 40.7184446,
"lng" : -74.0054619
}
}
},
"types" : [ "neighborhood", "political" ]
}
],
"status" : "OK"
}
Any better approach than using Google's geocoding API's bounding box?
This answer gives a link to polygonal city boundaries from TIGER data (so U.S. only): https://stackoverflow.com/a/10821465/3146587. The format is shapefile, but you can easily convert it to GeoJSON using ogr2ogr
for instance.
This blew my mind: all cities, states, countries for the planet in one big geojson file: https://mapzen.com/data/borders/
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