简体   繁体   中英

How to set longitude and latitude ranges for Bokeh Google Maps plot in Python?

I can only set zooms but I need to have a very specific position so I can overlay it over another plot. How I get a view just from the limits I specified below? Right now I can only set a zoom which is difficult for overlaying on another plot.

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap

output_file("gmap.html")

lat_lims = (42.418574999999997, 42.420059000000002)
lon_lims = (-70.907111, -70.904135999999994)
map_options = GMapOptions(lat=np.mean(lat_lims), lng=np.mean(lon_lims), map_type="satellite", zoom=18)

# For GMaps to function, Google requires you obtain and enable an API key:
#
#     https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
p = gmap(googlemaps_api_key, map_options)


show(p)

在此处输入图片说明

If you were running a Bokeh Server application, it is possible that the bounds could be returned back to Python in some way, but I'm afraid it is not possible in a standalone Bokeh document (ie HTML file) as you have. We are constrained by the using the Google maps API, and the bounds you are asking for are only available once the JavaScript code executes in the browser. The Google API does not accept arbitrary user provided bounds, it only accepts a center/zoom, or a suggested region. The real bounds are only computed and returned (to the browser) by Google API, and are never computed or available in Python.

You might look at the non-google TileProvider plots that are available. Unlike with GMap plots, you yourself can set the map bounds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM