Home > database >  How to display a google map in flask/django?
How to display a google map in flask/django?

Time:05-03

There's not much to be said about it except for the absence of any form of documentation having the least possible understandable way of doing it. Google's documentation only includes JS snippets that are good enough if I know how to use them in flask, django, or whatever python web framework.

CodePudding user response:

With Flask and Django you make HTML pages in the end, and from Flask you can just return some HTML with the parameters you need.

The Google maps embed API uses an iframe, so you can display a map on your page like this:

<iframe
  width="600"
  height="450"
  style="border:0"
  loading="lazy"
  allowfullscreen
  referrerpolicy="no-referrer-when-downgrade"
  src="https://www.google.com/maps/embed/v1/place?key=API_KEY
    &q=Space Needle,Seattle WA">
</iframe>

"You can set the Maps Embed API URL as the src attribute of an iframe" says the doc with that in https://developers.google.com/maps/documentation/embed/get-started

In your Flask or Django view thing, you can then have for example the geocoordinates of the map place you want, gmaps has had a nice API for ages.

  • Related