0

I am trying to add ol3 geocoder control in my project. I have set fix zoom level and it is working in Mozilla and it comes properly with appropriate zoom level but in google chrome it is not working. It takes the location on deep zoom in level. I have to zoom out to check surrounding places.

var geocoder = new Geocoder('nominatim', {
      provider: 'google',
      key:' AIzaSyClQ0GOW55zhw4PvFh73FyGLHdSd4bJfpM',
      lang: 'en',
      placeholder: 'Search Location...',
      limit: 5,
      keepOpen: true,
      autoComplete: true,
    });
    map.addControl(geocoder);


    //Listen when an address is chosen
    geocoder.on('addresschosen', function(evt){

      var
        feature = evt.feature,
        coord = evt.coordinate,
        address_html = feature.get('address_html');
      content.innerHTML = '<p>'+address_html+'</p>';


      if (coord) {
          //alert("if--");
          map.getView().setZoom(7);

          overlay.setPosition(coord);
        } else {

         map.getView().setZoom(8);
          overlay.setPosition(coord);
    }

    });
Subash
  • 3,128
  • 6
  • 30
  • 44
vyomaes
  • 1
  • 1
  • Hello and welcome to StackOverflow. Please review your code sample and fix it's formatting. This makes it easier for others to read and understand your problem. Please read the [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Clijsters Jan 31 '18 at 08:13

1 Answers1

0

When using the latest version of geocoder (3.0.1) it seems you can set the zoom level within the function. I had the same problem when I switched to new version, but I played around and found that it works perfectly like this:

geocoder.on('addresschosen', function (evt) {
    window.setTimeout(function () {
        view.setZoom(12);
        popup.show(evt.coordinate, evt.address.formatted);
    }, 1000);
});

Obviously, use whatever zoom value you like.

Todd
  • 30,472
  • 11
  • 81
  • 89