0

正规365体育投注I am doing my first app on Kivy where you can search for a particular product and it will show stores where you can get that product free of plastic packaging using the MapView widget from kivy garden. I am running into a problem where once the user has searched for the product they want to buy, it prints out the resulting stores, but it won't mark it on the map view of the app.

Markers showing general stores around the city already work, but I want the markers of the search results, showing the stores that carry the product without plastic, to appear on top of the old marker, but with a different icon.

searchpopup.py:

from kivymd.uix.dialog import MDInputDialog
from kivy.app import App
from deraptmap import DeraptMap


class SearchPopup(MDInputDialog):
    title = "Search by Product"
    text_button_ok = "Search"

    def __init__(self):
        super().__init__()
        self.size_hint = [0.9, 0.5]
        self.events_callback = self.callback

    def callback(self, *args):
        product = self.text_field.text
        print(product)
        self.get_stores_with_product(product)

    def get_stores_with_product(self, product):
        app = App.get_running_app()

        sql_search = "SELECT * FROM stores WHERE %s == 'Y'" \
                     % product
        app.cursor.execute(sql_search)
        stores_with_product = app.cursor.fetchall()

        print(stores_with_product)

        for store_with_product in stores_with_product:
            map_class = DeraptMap()
            map_class.store_with_product_marker(store_with_product)

storesmarker.py:

from kivy.garden.mapview import MapMarkerPopup
from storepopup import StorePopup


class StoresMarker(MapMarkerPopup):
    store_data = []

    def on_release(self):
        popup = StorePopup(self.store_data)
        popup.size_hint = [0.8, 0.9]
        popup.open()


class FreeStoresMarker(StoresMarker):
    source = 'marker-48.png'

Section of deraptmap.py The store_marker function works since the map shows markers of the stores around, but the store_with_product_marker isn't adding new markers with a different icon based on the search result. How do I get it to add new markers over the ones that are already on the map view?

from kivy.garden.mapview import MapView
from kivy.clock import Clock
from kivy.app import App
from storesmarker import StoresMarker, FreeStoresMarker


class DeraptMap(MapView):
    def store_marker(self, store):
        # Overlays the marker on the map with the coordinates
        lat, lon = store[2], store[3]
        marker = StoresMarker(lat=lat, lon=lon)
        marker.store_data = store
        self.add_marker(marker)

        # Keeps track of the stores with markers
        ID = store[0]
        self.store_IDs.append(ID)

    def store_with_product_marker(self, store):
        lat, lon = store[2], store[3]
        marker = FreeStoresMarker(lat=lat, lon=lon)
        self.add_marker(marker)
        print(store)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.