0

I am looking to get the Suburb from an input of an address or geocode (lat , lng or IP)

By Suburb I mean something like the following.

The UK Postcode : EH11 1AF is in the suburb of "Fountainbridge". There are many suburbs across the city of Edinburgh such as, "Haymarket, Barnton, Corstorphine, Comely Bank".

When I use the google reverse geocoding API such as :

/maps/api/geocode/json passing a lat,lng parameter

The response does not contain the suburb - see : http://maps.googleapis.com/maps/api/geocode/json?latlng=55.958712899999995,-3.216021&sensor=true

Is there an API which will help me to derive the suburb name based upon any part of a geocode or address, or postcode!? I am struggling to find such a service

RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
  • 2
    Have you looked at [geonames.org](http://www.geonames.org/)? – geocodezip Nov 30 '15 at 15:47
  • not sure how geonames.org actually gives me what I need geocodezip. For example this : http://www.geonames.org/postalcode-search.html?q=eh41ed&country=GB should yield the suburb name of 'Stockbridge' but does not. – RenegadeAndy Nov 30 '15 at 16:37
  • how do you define the boundaries of Stockbridge? Leith? Corstorphine? etc... it's not like postcodes or electoral boundaries. Where does Haymarket end and Corstorphine begin, as you're driving towards the zoo from Haymarket station, and so on? – duncan Nov 30 '15 at 16:40
  • Yeah - its a hard one duncan, I have no idea who even defines those boundaries, – RenegadeAndy Nov 30 '15 at 16:45

2 Answers2

0

Turns out geonames.org does indeed give what I need, take a look at this :

A latitude and longitude in Stockbridge, has a name of stockbridge: http://api.geonames.org/findNearbyPlaceNameJSON?formatted=true&lat=55.958712899999995&lng=-3.216021&username=demo&style=full tested it and it seems to work very well!

geocodezip
  • 158,664
  • 13
  • 220
  • 245
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
  • This is not an answer, should probably be re-written to be an answer or be posted as a comment on the question. – geocodezip Nov 30 '15 at 17:36
  • Sorry but it is exactly the right answer. I wanted to get the 'StockBridge' result from a latitude and longitude. This service call I have in the answer achieves this. It works for all UK cities, and also in the United States. What part of this does not answer my own question!? – RenegadeAndy Nov 30 '15 at 17:41
  • 2
    Sorry, it reads as a comment. If it is **the** answer perhaps you could re-write it to clearly address the question. I don't know what "geocode" has to do with it, maybe if that said "turns out geonames.org does indeed give what I need..." – geocodezip Nov 30 '15 at 17:44
  • Thats exactly what it said. – RenegadeAndy Dec 01 '15 at 13:36
  • OK, I fixed it to say that. – geocodezip Dec 01 '15 at 13:59
0

I feel your pain.

You get so much information from the Google API, while all you want is the suburb. Not to use another API.

Please correct if I am wrong, but you have two choices:

Choice 1: Iterate through the address_components till you find o component of type "locality".

Choice 2: Try the JSON location as:

    var guess = 5;
    var level = responseJSON.results[0].address_components.length-guess; 
    var suburb = responseJSON.results[0].address_components[level].short_name;

I know the choice 2 isn't an elegant solution and I wouldn't use it for critical applications, but so far it has been working for me.

When I pass my prototype on the project I am coding now, I will code the choice 1. Which is to look for the address_component marked type="locality".

I hope it helps.