API for converting lat-lon in New York neighborhood

Is there a hosted API that converts latitude and longitude to the Manakhtan area?

I know that Zillow has a shapefile , but I would rather use an API.

I looked at a few questions . Looks like NYC open data also has neighborhood information.

Closest I came to search for an API that uses lat lon, this is the Districts API, but it seems to be deprecated as it is not in their list of APIs and links are redirected to these lists.

Is there a public API? Or do I need to create a heroku application with a zillow shapefile and create my own?

Google maps only return manhattan in their geocoding response, not a specific area in Manhattan

+6
source share
2 answers

You can use the MapBox API to reverse geocode and parse the JSON data received to retrieve the neighborhood name. I made a small example from which you can inspire.

the 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

+2
source

There are several solutions for your purpose, such as CartoDB Integration , Bing Location API , geography , geocoder . strong>, API SmartyStreets and others.

Let's look at this using CartoDB :

Create a file with the coordinates of longitude and latitude in New York.

Use the Zillow New York neighborhood geometry file

Load the files in Cartodb and geoencode coordinates of longitude and latitude as a geometry object in your file of coordinates of longitude and latitude.

Run the following SQL query from a 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 create two inputFile as a and a shapefile as b , and then map the geometries to each other with a WHERE clause.

We are creating a new column with rows denoting the New York neighborhood for the longitude and latitude of the same row.

Just export the file in the desired format and enjoy the information.

You can easily automate the process using one of their integrations. This will act as the perfect API. See this

The python geopy also noteworthy. Check this

You can achieve the same result using the Bing Location API. See API

Another possible solution is to create your own API from open data.

Check out geocoder and SmartyStreets

+3
source

Source: https://habr.com/ru/post/1015448/


All Articles