Widget Maps Markers

what is the simplest way to add a map marker based on a database field?

greetings!

What do you plan to use as a map? Google map or Diorama widget?

hi and thanyou for reply its for google maps widget

Add the following code for Table widget to show Google Map label related to table row:

import QtQuick 2.5

Item {
    property string currentIndex: "0"
    
    Connections {
        target: document.childByName("Table 1").content.scriptAdaptor
        onEventItemIndex: {
            if (currentIndex == widget.content.currentIndex)
                return
            
            currentIndex = widget.content.currentIndex
            var lat = widgetUi.qmlModel.get(currentIndex,2)
            var lng = widgetUi.qmlModel.get(currentIndex,3)
            var label = widgetUi.qmlModel.get(currentIndex,1)
            
            // JavaScript code to run
            var js = "var myLatLng = {lat: "+lat+", lng: "+lng+"}; 
                // center map
                setLatLng(myLatLng.lat, myLatLng.lng)
                // show marker
                var marker = new google.maps.Marker({
                                position: myLatLng, 
                                map: map, 
                                title: 'Hello World!',
                                label: '" + label + "'});"        
        
            console.log("lat: " + lat + "; lng: " + lng + "; label: " + label)
            
            pageUi.getBlockByName("Map 1").contentUi.p_webView.backend.runJavaScript(js)
        }
    }
} 

Based on this Google Maps Api example https://developers.google.com/maps/documentation/javascript/examples/marker-simple

See the example table_to_googlemap_marker.pma (991.2 KB)


Back to Flipabit >
Copyright © 2018. Flipabit Team. All rights reserved.