0

我正在使用nokia.places.widget.SearchBoxnokia.maps.map.Display

当用户从结果列表中选择一个项目时,您可以使用 SearchBox 的 onSelect 函数来执行操作。

我需要做的是将地图居中并缩放到所选位置。我的问题是关于缩放,因为我不知道要使用什么级别。

我注意到有些地方有 boundingBox(与 Display 组件的zoomTo函数一起使用)属性,但其他地方没有。我可以使用类别('administrative-region''street-square'等),但它不是精确的,而且我找不到可能的类别代码列表。

有什么建议吗?

4

1 回答 1

1

要在选择建议时让地图移动/缩放到某个位置,您需要实现一个onResults处理程序:

var fromSearchBox = new nokia.places.widgets.SearchBox({
    targetNode: "fromSearchBox",
    template: "fromSearchBox",
    map: map,
    onResults: function (data) {
        // Your code goes here //

    }
});

正如您所注意到的,该data字段可能包含也可能不包含边界框。这是因为只有少数几个位置覆盖了一个定义的区域,大多数是地址。

对于具有边界框的子集,您可以执行以下操作:

if (data.results.items[0].boundingBox){
    map.zoomTo(data.results.items[0].getBoundingBox());
}

对于其余部分,答案将取决于您要达到的目标,但您可以尝试以下任何一种方法:

  • 在不改变缩放的情况下移动到地图上的位置。(即让用户决定)

    map.set("center", data.results.items[0].position);
    
  • 移动到指定位置的点对象的指定边界框。

    var obj = new nokia.maps.map.StandardMarker(startPoint);
    map.zoomTo(obj.getBoundingBox());   
    

或者:map.zoomTo(nokia.maps.geo.BoundingBox.coverAll([startPoint]));

  • 定义围绕点位置的边界框并缩放到该位置

    startPoint =data.results.items[0].position;
    bottomLeft = new nokia.maps.geo.Coordinate(startPoint.latitude - 0.1,
             startPoint.longitude + 0.1);
    topRight = new nokia.maps.geo.Coordinate(startPoint.latitude + 0.1,
             startPoint.longitude - 0.1);
    map.zoomTo(nokia.maps.geo.BoundingBox.coverAll([topRight, bottomLeft]));
    

Additionally, Display.zoomTo() can also take an additional parameter, so if you use map.zoomTo(BoundingBox, true) you will also keep the current center for the map on screen, and this may give more context to a user.

于 2013-09-16T13:25:41.873 回答