根据输入的地理编码位置,从数据库中显示落在地图边界内的传单标记

加思·法比恩

我有一个 GUI 应用程序,其中我的数据库中的数据显示在表格上,并在传单地图上显示为标记。我已将 Geocode ( L.Control.geocoder() ) 函数添加到我的应用程序中,现在想要显示我的数据库中适合我的 Geocode 位置所在地图边界的标记。

我已经阅读了传单文档中的 map.toBBoxString() 和 map.getBounds() ,这是我认为我需要进行比较并为我的数据库数据编写查询以显示在输入的“地理编码”位置的内容. 我的问题是我不知道如何获取实际值并对我的 Python 查询进行比较。下面是我的代码的搜索按钮部分,它连接到函数以显示用户在 table 和 map 上输入的数据。

def search_all(self):


        print ('Searching All...')
        looking = str(self.lookall.text())       
        if looking == "":
            QMessageBox.about(self, "No Info ", " Please enter value ")         
        else :

            conn = #connection to DB

            cursor = conn.cursor()        
            query = "SELECT*FROM CT_ALL_F WHERE Lic_no LIKE  '%s' OR Licensee LIKE '%s' OR FREQ LIKE '%s' OR Power LIKE '%s' OR Installation_address LIKE '%s' OR Business_address LIKE '%s' OR Tel LIKE '%s' " %('%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%')        
            cursor.execute(query)    
            results = cursor.fetchall()

            self.tableWidget.setRowCount(0)            
            for row_number, row_data in enumerate(results):                
                self.tableWidget.insertRow(row_number)                
                for column_number, data in enumerate (row_data):                                        
                    self.tableWidget.setItem(row_number,column_number,QtWidgets.QTableWidgetItem(str(data)))                    
                    pass
                pass

                coordinates = []

                for result in results:        
                    coordinates.append((result[5], result[6] ,(result[0], result[1],result[2],result[3],result[4])))


                lat_center = sum([coordinate[0] for coordinate in coordinates]) / len(coordinates)
                lng_center = sum([coordinate[1] for coordinate in coordinates]) / len(coordinates)

                html = """
                        <!DOCTYPE html>
                        <html>
                        <head>
                        <style type="text/css">
                                html { height: 100%; }
                                body { height: 100%; margin: 0; padding: 0 }
                                #mapid { height: 100% }
                        </style>
                        <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
                        <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>

                        <link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css" />
                        <script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js"></script>


                        </head>
                        <body>
                        <div id="mapDiv" style="width:100%; height:100%"</div>
                        <script>

                        """

                html += "var map = L.map('mapDiv').setView([{lat}, {lng}], 10);".format(lat=lat_center, lng=lng_center)                
                html += """
                        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                        attribution: '&copy; <a href="https://www.icasa.org.za/">ICASA</a> <br> <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
                        }).addTo(map);

                        """

                for latitude, longitude , frequency in coordinates:

                    html += "var marker = L.marker([{lat}, {lng}]);\n ".format(lat=latitude, lng=longitude)                   
                    html += "var popupLocation1 = new L.LatLng({lat}, {lng});".format(lat=latitude, lng=longitude )                    
                    html += """var popupContent1 = ("License number : {freq}<br>Licensee: {dek}<br>Frequency : {lek}<br>Power : {sek}<br>Location : {mek}<br>"),""".format(freq=frequency[0],dek=frequency[1],lek=frequency[2],sek=frequency[3],mek=frequency[4])
                    html += "popup1 = new L.Popup();"
                    html += "popup1.setLatLng(popupLocation1);"
                    html += "popup1.setContent(popupContent1);"
                    html+= "marker.bindPopup(popupContent1);"
                    html += "map.addLayer(popup1).addLayer(marker);"

                    html += "L.Control.geocoder().addTo(map);</script> </body> </html>"
                self.view.setHtml(html)

在输入地理编码位置后,我希望从我的数据库中看到位于地图地图边界内的标记,并显示在我的传单地图上

我的示例数据库在此处输入图片说明

加思·法比恩

我将数据类型从我的 Ms Access DB 更改为短文本,这使我能够使用从 geocoder 获得的边界框坐标从我的数据库结果中编写比较查询。这有效

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何显示Firebase数据库中的所有标记?

在Swift中反向地理编码位置

角度Google Maps获取地图边界内的所有位置

数据库中的标记聚类位置

我的循环创建了Google地图标记,但无法正确设置其位置,因此无法显示。硬编码位置作品

通过地理位置过滤位置的数据库设计

Sqflite数据库中Flutter地图上的Flutter标记位置(纬度,经度)

如何通过从数据库中提取所有坐标来使用传单在地图上放置标记?

对于要进行HTTPS地理编码api调用的循环,并在结果中将坐标输入到SQL数据库中,如何使Node的HTTPS模块起作用?

在数据库中的Google地图(API V2)上显示多个标记

使用AJAX将给定位置与SQL数据库中存储的地理编码进行比较

如何将传单标记与数据库中的对象ID相关联

谷歌地图-功能地理编码和标记

如何根据存储在数据库中的地理位置找到行进的总距离

带输入框的传单地理编码

根据位置从外部数据库中获取数据

传单地理搜索-从传单地图容器外部搜索位置

数据库中的动态站点地图不显示节点

从数据库加载的位置未显示Google Map标记

必应地图需要根据城市和DK的邮政编码显示位置边界多边形

sqllite代码位置一的数据库位置

根据数据库列中的值显示输入字段的数量

在tableviewController中反向地理编码位置

传单地图添加、编辑、删除带有 id 的数据库中的形状

使用传单 esri 插件对数据库中的地址名称进行地理编码

我可以将 HERE 地理编码 API 结果存储到数据库中吗?

使用 Laravel 中的传单从数据库中标记位置

搜索时如何使用数据库中的 PHP 在 Google 地图中显示多个标记?

反应传单中的地图标记未正确显示图像