Skip to content

Return Coordinates values on PYQt #1488

@RicardoMessala

Description

@RicardoMessala

Hello everyone! i'm a Python newbie and this is my Python test code PYQt + Folium. I've already searched a lot and i know about the bi-directional question about folium. But as im using PYQt and saving the file, i'd like to know if there is some way to return the coordinates values when i click on the map. In this example i can vizualise the coordinates using LatLng, but as im a Python newbie i dont know if i can get these values.

import sys
import io
import folium
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView

class MyApp(QWidget):

def __init__(self):
    super().__init__()
    self.setWindowTitle('Folium in PyQt Example')
    self.window_width, self.window_height = 1600, 1200
    self.setMinimumSize(self.window_width, self.window_height)
    layout = QVBoxLayout()
    self.setLayout(layout)
    local = [[28.63382, 77.22045], [28.63458, 77.22100], [28.63514, 77.22142],
             [28.63517, 77.22146], [28.63519, 77.22151], [28.63518, 77.22158], [28.63518, 77.22158],
             [28.63499, 77.22180], [28.63471, 77.22212], [28.63442, 77.22238], [28.63411, 77.22260],
             [28.63390, 77.22272], [28.63368, 77.22282], [28.63345, 77.22290], [28.63313, 77.22297],
             [28.63281, 77.22299], [28.63249, 77.22298], [28.63217, 77.22293], [28.63186, 77.22283],
             [28.63141, 77.22256], [28.63141, 77.22256], [28.63129, 77.22258], [28.63121, 77.22259],
             [28.63113, 77.22266], [28.63072, 77.22335], [28.63063, 77.22353], [28.63059, 77.22359],
             [28.63046, 77.22381], [28.63043, 77.22388], [28.62914, 77.22615], [28.62914, 77.22615],
             [28.62922, 77.22648], [28.62923, 77.22651], [28.62924, 77.22653], [28.62925, 77.22655],
             [28.62926, 77.22657], [28.62935, 77.22665], [28.62937, 77.22667], [28.62938, 77.22669],
             [28.62939, 77.22672], [28.62943, 77.22682], [28.62943, 77.22682], [28.62972, 77.22701],
             [28.63027, 77.22744], [28.63436, 77.23048], [28.63456, 77.23060], [28.63482, 77.23072],
             [28.63511, 77.23084], [28.63545, 77.23091], [28.63581, 77.23095], [28.63656, 77.23101],
             [28.63673, 77.23102], [28.63824, 77.23116], [28.63985, 77.23134], [28.64039, 77.23144],
             [28.64039, 77.23144], [28.64049, 77.23147], [28.64038, 77.23156], [28.64022, 77.23153],
             [28.64022, 77.23153]]
    
    coordinate = ([28.63382, 77.22045])
    m5 = folium.Map(
        tiles='https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png',
        attr='copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a '
             'href="http://cartodb.com/a:ttributions">CartoDB</a>,CartoDB <a href '
             '="http//cartodb.com/attributions">attributions</a>', 
        zoom_start=15,
        location=coordinate
    )
    folium.features.LatLngPopup().add_to(m5)
    folium.PolyLine(local, color='blue').add_to(m5)
    folium.LayerControl().add_to(m5)

    # save map data to data object
    data = io.BytesIO()
    m5.save(data, close_file=False)
    webview = QWebEngineView()
    webview.setHtml(data.getvalue().decode())
    layout.addWidget(webview)

if name == 'main':
app = QApplication(sys.argv)
myApp = MyApp()
myApp.show()

try:
    sys.exit(app.exec_())
except SystemExit:
    print('Closing Window...')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions