I wanted output with links like these for my objects:

Brazil <http://www.montao.com.br> > São 
Paulo<http://www.montao.com.br/sao_paulo>> São 
Bernardo do Campo <http://www.montao.com.br/sao-paulo/sao-bernardo-do-campo> 

or

India <http://www.koolbusiness.com/> > 
Maharashtra<http://www.koolbusiness.com/maharashtra>> 
Mumbai <http://www.koolbusiness.com/maharashtra/mumbai>

I think that serverside works better than javascript and I'd like you to 
comment this. I used javascript reverse geocoding for some time and found 
it unfavorable since it renders after the page is loaded. I'd like to see a 
serverside solution using JSON or XML to my problem, I asked 2 questions 
about it on stackoverflow and this week it appears solved and I wonder if 
you can comment or answer eg. why these functions are not directly 
available from the API. Since I'm using the grouping 
/<region>/<city>/<category>? to retrieve my objects combined with a 
db.geopt for every object I liked to see a solution 
and we solved it at SO where you may compare 2 solutions: 
http://stackoverflow.com/questions/8395252/how-to-reverse-geocode-serverside-with-python-json-and-google-maps
I will reward the answer a bounty since this was important for me and the 
answer is very neat (I also published a solution that "works" but is not as 
pythonistic as the one from the answer.)

The answer I was sent that does it is

 import json
import urllib2

def get_geonames(lat, lng, types):
    url = 'http://maps.googleapis.com/maps/api/geocode/json' + \
            '?latlng={},{}&sensor=false'.format(lat, lng)
    jsondata = json.load(urllib2.urlopen(url))
    address_comps = jsondata['results'][0]['address_components']
    filter_method = lambda x: len(set(x['types']).intersection(types))
    return filter(filter_method, address_comps)

lat, lng = 59.3, 18.1
types = ['locality', 'administrative_area_level_1']

# Display all geographical names along with their types
for geoname in get_geonames(lat, lng, types):
    common_types = set(geoname['types']).intersection(set(types))
    print '{} ({})'.format(geoname['long_name'], ', '.join(common_types))



IMHO the google geocoding API is missing these functions: 
 
   - admin_area.get_localities
   - country.get_admin_areas
   - point.get_admin_area_level_1 (state/region)
   - point.get_locality (city)

A link to the javascript question about this is 
http://stackoverflow.com/questions/8394759/how-to-get-the-region-city-from-a-geocoding-object/8394840#8394840
And a link to my map using this technology (now with the server code 
instead of javascript) is http://www.montao.com.br/vi/4414192.html
where it clearly works printing the state (Sao Paulo) and the city (Sao 
Bernando do Campos) and there is no confusion which is the region and which 
is the city anymore. 
Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-maps-js-api-v3/-/iYumnkY0b6oJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

<<attachment: crumbs-br.png>>

<<attachment: crumbs-in.png>>

Reply via email to