2

解決策はそれほど遠くないことはわかっていますが、ユーザー入力に基づいて数値をマップ縮尺に割り当てる機能を実装するのに苦労しています。コードは一目瞭然ですが、入力を使用して 4 つのズーム状態からユーザーが選択し、ズームの開始点としてマップに数値を返すようにしたいと考えています。

zoom=5
while True:
    where = raw_input('Where would you like a map of?')
    try:
        heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
        pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
    except AttributeError, GeocoderServiceError:
        print "Cannot create map with the given location. Please try again."
    else:
        break
while True:
    zoom_state = ['city', 'state', 'country', 'world']
    zoom_state= raw_input('What level of detail would you like: city, state, country, or world?')
    try:
         for response in zoom_state:
            if response is ['city']:
                zoom == 9
                if response is ['state']:
                    zoom == 7
                    if response is ['country']:
                        zoom == 5
                        if response is ['world']:
                            zoom == 9 
    except TypeError, IndexError:
        print 'Please enter: city, state, country, or world. Try again'
        continue
    else:
        break

heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)

現在のところ、zoom_state には何でも入れることができ、実行されます。

前もって感謝します!

4

1 に答える 1

2

次のようなものを探しているかもしれません:

zoom=5
while True:
    where = raw_input('Where would you like a map of?')
    try:
        heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
        pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
    except AttributeError, GeocoderServiceError:
        print "Cannot create map with the given location. Please try again."
    else:
        break
while True:
    zoom_level = {'city':9, 'state':7, 'country':5, 'world':9}
    zoom_detail = raw_input('What level of detail would you like: city, state, country, or world?')
    try:
         zoom = zoom_level[str(zoom_detail)]
    except TypeError, IndexError:
        print 'Please enter: city, state, country, or world. Try again'
        continue
    else:
        break

heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
于 2016-03-09T20:34:42.953 に答える