<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def geo_map(h2, map=None, tiles='stamenterrain', cmap="wk", alpha=0.5, lw=1, fit_bounds=None, layer_name=None):
 """Show rectangular grid over a map. Parameters h2: physt.histogram_nd.Histogram2D A histogram of coordinates (in degrees: latitude, longitude) map : folium.folium.Map Returns ------- map : folium.folium.Map """

    if not map:
        latitude = h2.get_bin_centers(0).mean()
        longitude = h2.get_bin_centers(1).mean()
        zoom_start = 10
        map = folium.Map(location=[latitude, longitude], tiles=tiles)
        if fit_bounds == None:
            fit_bounds = True

    geo_json = _bins_to_json(h2)

    if not layer_name:
        layer_name = h2.name

    from branca.colormap import LinearColormap

    color_map = LinearColormap(cmap, vmin=h2.frequencies.min(), vmax=h2.frequencies.max())

    # legend = folium.Html("<div>Legend</div>")
    # legend_div = folium.Div("20%", "20%", "75%", "5%")
    #
    # legend_div.add_to(map)
    # legend_div.add_child(legend)

    #xx = h2.frequencies.max()

    def styling_function(bin):
        count = bin["properties"]["count"]
        return {
            "fillColor": color_map(count),
            "color": "black",
            "fillOpacity": alpha if count > 0 else 0,
            "weight": lw,
            # "strokeWidth": lw,
            "opacity": alpha if count > 0 else 0,
        }# .update(styling)

    layer = folium.GeoJson(geo_json, style_function=styling_function, name=layer_name)
    layer.add_to(map)
    if fit_bounds:
        map.fit_bounds(layer.get_bounds())
    return map