Search code examples
pythonbokeh

Center bokeh tile provider map around specific GPS coordinates


Using bokeh example of displaying mercator map here, how do I center the map around a specific set of GPS coordinates?

from bokeh.plotting import figure, output_file, show
from bokeh.tile_providers import CARTODBPOSITRON_RETINA, get_provider

output_file("tile.html")

tile_provider = get_provider(CARTODBPOSITRON_RETINA)

# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
           x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(tile_provider)

show(p)


Solution

  • After you got the tile_provider you can change the default values like below:

    tile_provider.x_origin_offset = 20037508.34
    tile_provider.y_origin_offset = 25037508.34
    tile_provider.initial_resolution = 180000
    

    new focus for a map