Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a table called osm_places with place_name geometry, place_type and many other info related to the city. My database system is PostGIS.

My requirement is:

Given a latitude and longitude (which may or many not be the exact lat and long stored in the database), I need to find the nearest city or place_name from the table osm_places with the help of the input latitude and longitude. Any help is highly appreciated.

Is there a nearest neighbor implementation in php available for this or SQL to handle this?

share|improve this question
    
Need more information about your setup. Is it PostGIS or Microsoft or something else? –  Taylor H. Feb 4 '13 at 15:01
add comment

2 Answers

There is a function in pgRouting called find_node_by_nearest_link_within_distance(), which does exactly what you need. See http://underdark.wordpress.com/2011/10/11/a-look-at-pgrouting-find_node_by_nearest_link_within_distance/

share|improve this answer
add comment

Geonames API can also do this - you will need an account:

Live Demo http://api.geonames.org/findNearbyJSON?lat=47.3&lng=9&username=demo

Example - but you need to use your own account (replace username=demo) http://api.geonames.org/findNearbyJSON?lat=51.507689&lng=-0.127934&username=demo

Documentation http://www.geonames.org/export/web-services.html#extendedFindNearby

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.