Is there a hosted API that converts a latitude and longitude into a Manahttan neighborhood?
I know that Zillow has a shapefile but I'd much rather just use an API.
I've looked a few questions. It looks like NYC open data also has neighborhood information.
The closest I've come to finding an API that takes lat lon is the times Districts API but it seems to be deprecated as it's not on their list of API's and the links redirect to those lists.
Is there a publicly available API? Or do I need to create a heroku app with a zillow shapefile and create my own?
Google maps only returns manhattan in its geocoding response, not a specific neighborhood in Manhattan
One way to find your geolocation is to simply perform a lookup online. Melissa's Geocoder Lookup tool returns latitude, longitude, county, census tract and block data based on an address or ZIP Code. Simply enter the address or ZIP Code into the easy-to-use Lookups interface and submit.
You can use MapBox API for reverse geocoding and parse the JSON data obtained to extract the Neighborhood name. I made a small example that you can inspire from.
Code:
//You can get your access_token if needed from mapbox.com
var access_token = '?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
var urlInit = 'https://api.mapbox.com/geocoding/v5/';
var mode = 'mapbox.places/';
var type = '&types=neighborhood';
$('#go').click(function() {
$('#result').html('');
lonlatInput = $('#lonlat').val();
lonlatInput = lonlatInput.split(',');
lonlat = lonlatInput[0].trim() + '%2C' + lonlatInput[1].trim() + '.json';
getNeighborhood(lonlat);
});
function getNeighborhood(lonlat) {
var url = urlInit + mode + lonlat + access_token + type;
$.ajax({
type: 'GET',
url: url,
success: function(rgeo) {
var result = rgeo;
var neighborhood = rgeo.features[0].text;
$('#result').html(neighborhood);
},
error: function(rgeo) {
console.log(rgeo);
}
});
}
#result {
padding: 10px;
font-size: 2em;
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="-73.945462,40.830182" id="lonlat" />
<button id="go">Geocode</button>
<div id="result"></div>
See this example in JsFiddle
There are a couple of solutions to your objective such as CartoDB integrations, Bing Location API, geopy, geocoder, SmartyStreets API and others.
Let us explore this using CartoDB:
Create a file with longitude and latitude coordinates in NYC.
Use an NYC neighborhoods geometry file from Zillow
Upload the files to Cartodb and geoencode the longitude and latitude coordinates as a geometry object in your longitude and latitude coordinate file.
Run the following SQL query from within the file:
SELECT a.*,
b.neighborhood
FROM inputFileName
as a,
nyc_pediacities_neighborhoods_v3_polygon as b
WHERE ST_Within(a.the_geom,b.the_geom)
We are creating two objects, inputFile
as a
and the shapefile
as b
, then match the geometries against one another with the WHERE clause.
We are creating a new column with rows denoting the NYC neighborhood of the longitude and latitude of the same row.
Simply export the file in a desirable format and enjoy the information.
One can easily automate the process using one of their integrations. This will closely act as an ideal API. See this
The python package geopy
also deserves attention. Check this
One can achieve the same result using the Bing Location API. See API
Another feasible solution is to construct your own API from the open data.
Check geocoder and SmartyStreets
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