1

I am looking for an api that I can use to find nearby cities based on coordinates or name and country(maybe with a feature to filter by distance as nearby can be up to interpretations).

I would prefer it to be restful or have a library(wrapper) that I can use in my .net application.

I am looking for a free api(with a good amount of free requests per day).

My first thought was Google and I found "The Google Geocoding API" but I am not planning to put it on a map so according to the limitations I cannot use it.

Anyone else know of any other ones that I could use?

Icemanind
  • 47,519
  • 50
  • 171
  • 296
chobo2
  • 83,322
  • 195
  • 530
  • 832
  • 1
    It would be pretty hard to sue it, perhaps this will help: http://stackoverflow.com/questions/11399069/alternative-to-google-maps-geolocation-api – Jeremy Thompson Apr 11 '13 at 23:04
  • I think you can use google geocoding API's , just make your map invisible or just not map it to the div where your map is. – Chetan Apr 12 '13 at 07:04
  • There's a bunch of location-oriented APIs collected here: https://www.temboo.com/library/keyword/location/ – Cormac Driver Apr 12 '13 at 14:28
  • @CormacDriver - Ya I thought of ones like foursquare and such but I can't find anything in the api that will help me find nearest cities. If you know please provide me with some documentation or better yet a sample. – chobo2 Apr 12 '13 at 17:47
  • I looked into this and Geocoding is the best option. I didn't see where the terms of services rules out using the results of the API in a non-map interface though. – Cormac Driver Apr 12 '13 at 18:30
  • "Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the " – chobo2 Apr 12 '13 at 18:41

2 Answers2

1

Try looking at GeoNames. They have a RESTful API you can use to do reverse geocoding. Scroll down to the "Find nearby postal codes / reverse geocoding" section to see a live demo.

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • I think they charge money. I tried their find postal code in the first link and it could not even locate mine. – chobo2 Apr 12 '13 at 06:11
  • I been looking more into them. I do see you can download cities and such but what confuses me is some cities are listed multiple times with different coordinates(sometimes slightly off). No clue what to use then. – chobo2 Apr 26 '13 at 21:52
1

You could try using the Overpass API, this uses Open Street Map data. I'm not sure if it will do exactly what you are after but it may be a start.

The call below searches for cities. The bbox creates an area to search within. The example I have created below uses coordinates that surround Portsmouth, UK.

http://overpass.osm.rambler.ru/cgi/xapi?node[place=city][bbox=-1.150818,50.761653,-0.987396,50.851908]

The results returned from this provides some useful data

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API">
    <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
    <meta osm_base="2013-04-11T23:39:03Z"/>
    <node id="17721995" lat="50.8065249" lon="-1.0744016">
        <tag k="is_in" v="EnglaHampshire, England, UK"/>
        <tag k="is_in:continent" v="Europe"/>
        <tag k="is_in:country" v="United Kingdom"/>
        <tag k="is_in:country_code" v="GB"/>
        <tag k="is_in:county" v="Hampshire"/>
        <tag k="name" v="Portsmouth"/>
        <tag k="name:ru" v="Портсмут"/>
        <tag k="name:sr" v="Портсмут"/>
        <tag k="place" v="city"/>
        <tag k="population" v="197700"/>
        <tag k="url" v="http://www.visitportsmouth.co.uk"/>
    </node>
</osm>

I do believe it is possible to replace the coordinates with other search functions such as a country name.

EDIT:

http://overpass-api.de/ with query base address http://overpass-api.de/api/ (4 cores, 64 GB RAM). http://overpass.osm.rambler.ru/ with query base address http://overpass.osm.rambler.ru/cgi/ (8 cores, 64 GB RAM).

Both servers have a total capacity of about 1.000.000 requests per day. You can safely assume that you don't disturb other users when you do less than 10.000 queries per day or download less than 5 GB data per day.

marcbest
  • 1,600
  • 1
  • 10
  • 15
  • Sorry. I am not following(maybe because I am not that familiar with the UK area) how I could use this. I will get a longitude and latitude from the phone. Are you saying I should add to these numbers to get an area or something? – chobo2 Apr 12 '13 at 17:53
  • I would point out this may not be the most efficient way of doing this, I havent looked into this API or others in much depth. But yes receive the lat and lon from the phone, this will be your center position. Then from this position you would have to work out the coordinates of the area you would like to search for cities in e.g 10 miles. I havent implemented anything like this but in the link is a C# example of the formula for working this out. http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location – marcbest Apr 12 '13 at 22:57
  • The Overpass API uses a box to search for locations. So you would need to provide the bottom left and top right latitude and longitude coordinates to make up this area. – marcbest Apr 12 '13 at 23:02