Skip to content

Using GoogleMaps Tile instead of default folium map tiles #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SumeetSandhu opened this issue Jan 14, 2025 · 5 comments · Fixed by #2082
Closed

Using GoogleMaps Tile instead of default folium map tiles #2079

SumeetSandhu opened this issue Jan 14, 2025 · 5 comments · Fixed by #2082
Labels
documentation Documentation about a certain topic should be added

Comments

@SumeetSandhu
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

googlePlex = ( 37.423199 , -122.084068 )
z,x,y = 10, 164, 397

map1 = folium.Map(tiles='https://mt1.google.com/vt/lyrs=r&x='+str(x)+'&y='+str(y)+'&z='+str(z), attr='GoogleMap')
map1

map2 = folium.Map(tiles='https://tile.googleapis.com/v1/2dtiles/'+str(z)+'/'+str(x)+'/'+str(y)+'?session='+GMAPS_SESSION_KEY+'&key='+GMAPS_API_KEY,attr='GoogleMap')
map2

Expected behavior
Map1 shouldn't work at all without credentials but it does open something weird - a grid of copies of the desired tile's thumbnail. Probably a google authentication error? The tiles are of the newer upcoming style.

Map2 gives the same error - a grid of copies of the desired tile's thumbnail. The tiles are of the current, older style.
This is likely a folium error?

Environment (please complete the following information):

Additional context
Add any other context about the problem here.

Possible solutions
List any solutions you may have come up with.

folium is maintained by volunteers. Can you help making a fix for this issue?

@SumeetSandhu SumeetSandhu changed the title Using GoogleMaps Tile Using GoogleMaps Tile instead of default folium map tiles Jan 14, 2025
@Conengmo
Copy link
Member

Conengmo commented Jan 15, 2025

Not sure what you are talking about really, and I don't have an API key so I can't verify. Are you sure the url you use is correct? You are likely not supposed to put those numbers into the url. Instead it should look something like this: https://tile.googleapis.com/v1/2dtiles/{z}/{x}/{y}.png?key=YOUR_API_KEY. Note how z, x and y are not replaced with numbers in the url, as this is actually a template url.

If there is an issue here, it's likely in somewhere between Leaflet and the Google API. Not much we can do in Folium.

@Conengmo Conengmo closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@SumeetSandhu
Copy link
Author

SumeetSandhu commented Jan 15, 2025

I guess the question then becomes - are Leaflet plugins supported by Folium? I see a lot of Google Maps related plugins at https://leafletjs.com/plugins.html such as https://gitlab.com/IvanSanchez/Leaflet.GridLayer.GoogleMutant.

Also, Google returns one tile at a time - which means we have to fetch a lot of high resolution X-Y tiles to compose the map for a given location at a given Zoom.

@hansthen
Copy link
Collaborator

@SumeetSandhu,

I agree with @Conengmo that there are a few issues in the code sample you sent us. You might want to try the following first: You should not hardcode the x, y and z values in the tile url. They should be literal "x={x}" etc. Leaflet itself will replace these template strings with the appropriate values for the tile. This should solve your repeating tiles in a grid issue.

The other issue (the older style tiles) is highly unlikely to be Folium related. Folium is just a thin wrapper around Leaflet. As stated, we just pass a url string to Leaflet to tell it where to fetch the tiles. I know this is a hard ask, but for issues like this, I want to see a working example in pure Leaflet before accepting this as a Folium issue.

@SumeetSandhu
Copy link
Author

Thank you @Conengmo and @hansthen - the following worked

It would be great to add them to official documentation because there are many versions floating around on random youtube videos :)

@Conengmo
Copy link
Member

Good to hear it worked! And thanks for the suggestion, I opened a PR to expand our documentation on this topic a little bit.

@Conengmo Conengmo reopened this Jan 18, 2025
@Conengmo Conengmo added the documentation Documentation about a certain topic should be added label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation about a certain topic should be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants