0

我正在使用QML PlaceSearchModelQML GeocodeModel的组合(也尝试使用PlaceSearchSuggestionModel在搜索地图时生成搜索建议列表;但是当我开始输入时,我的下拉列表中只显示国家(见图1)

我的目标不仅是显示“地址”,而且还显示地点(例如,当您开始搜索时,您当地的快餐连锁店)因为这样做的目的是为应用程序内的事件标记位置。

我一直在关注/改编我在网上找到的类似教程,运行代码如下:

搜索字段

Column {
    anchors.fill: parent;
    AppTextField {
        id: searchTextField; 
        width: parent.width; 
        onAccepted: {focus = false; if (text != "") {geocodeModel.query = text}}
                        onDisplayTextChanged: {
                                suggenstionModel.searchTerm = searchTextField.displayText.toString();
                                suggenstionModel.update()
                        }
                    }
    SuggestionsList {
        id: suggestionsList; 
        model: suggenstionModel; 
        onProposalSelected: {
            searchTextField.focus = false; 
            searchTextField.text = suggestion; 
            geocodeModel.query = suggestion
        }
    }
} //column end

QL.GeocodeModel {
    id: geocodeModel; 
    plugin: MapBoxPlugin {geocoding: true} 
    autoUpdate: true
    onLocationsChanged: {
        for(var i = 0; i < count; i++){
                var address = get(i).address
                var fullText
                fullText = "str: "+ address.street + " City: " + address.city + " Country: " + address.country

    //This loop logs all the full addresses in my console.
            }
        }
    }
QL.PlaceSearchModel {
    id: suggenstionModel; 
    plugin:  MapBoxPlugin {geocoding: true}
    onStatusChanged: {
        if (status == QL.PlaceSearchSuggestionModel.Ready) {
            suggestionsList.show()
        }
    }
}

建议列表.qml

AppListView {
  id: root

  property real rowHeight: dp(30)
  property int fontPixelSize: sp(12)

  signal proposalSelected(string suggestion)

  height: 0
  visible: false
  clip: true

  boundsBehavior: Flickable.StopAtBounds

  delegate: SimpleRow {
    height: root.rowHeight
    text: place.location.address.text
    onSelected: {
      root.proposalSelected(place.location.address.text)
    }
  }

我的问题是 ,如何使用 PlaceSearchModel/PlaceSearchSuggestionModel 和地理编码模型,不仅可以搜索实际的“地点”及其地址,而且如何在建议列表中完整显示这些?

图片 1

图片1

图 2 在此处输入图像描述

4

0 回答 0