打开图层3搜索功能以查找地图位置?

Nic*_*s T 6 search google-maps openlayers-3

将搜索功能实现到OL3映射的最佳方法是什么?

我需要一个搜索输入,它会在搜索时向我显示一些选项,然后平移和缩放到特定的搜索词.非常像谷歌地图.

我需要将谷歌地图集成到我的OL3中吗?

Jon*_*ker 14

Openlayers 3中没有原生的搜索/ 地理编码器.但是你可以使用ol- geocoder 扩展(我写过它)来满足这种需求.

说明位于提供的链接中.我只想说明我一般如何使用它:

//Instantiate with some options and add the Control
var geocoder = new Geocoder('nominatim', {
  provider: 'google',
  lang: 'pt-BR',
  placeholder: 'Pesquise por um endereço',
  limit: 5,
  key: '....',
  keepOpen: false,
  debug: true
});
map.addControl(geocoder);

// I don't want/need Geocoder layer to be visible
geocoder.getLayer().setVisible(false);

//Listen when an address is chosen
geocoder.on('addresschosen', function(evt){
  var feature = evt.feature;
  var coord = evt.coordinate;

  // application specific
  app.addMarker(feature, coord);
});
Run Code Online (Sandbox Code Playgroud)