Searchbox Google Maps JS API does not return search results

Asked

Viewed 371 times

0

Good evening, I have a map obtained through the Google Maps Javascript API, and I’m inserting a searchBox. So far so good, the search box has been inserted and the autocomplete is working. The problem is that when the "upload" of the field is done, or selected some location by autocomplete, nothing happens on the map (does not return the searched result) as you can see here http://suconago.com.br/maps/.

What do I have to insert to the JS to get the search results back? If possible, without the points that are marked disappear, just take the map focus to the selected place, marking it.

Thank you.

1 answer

0


I managed to solve. I replaced the excerpt

var input = document.getElementById('pac-input');
            var searchBox = new google.maps.places.SearchBox(input);
            map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

            map.addListener('bounds_changed', function() {
                searchBox.setBounds(map.getBounds());
            });

for

				   var searchBox = new google.maps.places.SearchBox(document.getElementById('pac-input'));
   map.controls[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById('pac-input'));
   google.maps.event.addListener(searchBox, 'places_changed', function() {
     searchBox.set('map', null);


     var places = searchBox.getPlaces();

     var bounds = new google.maps.LatLngBounds();
     var i, place;
     for (i = 0; place = places[i]; i++) {
       (function(place) {
         var marker = new google.maps.Marker({

           position: place.geometry.location
         });
         marker.bindTo('map', searchBox, 'map');
         google.maps.event.addListener(marker, 'map_changed', function() {
           if (!this.getMap()) {
             this.unbindAll();
           }
         });
         bounds.extend(place.geometry.location);


       }(place));

     }
     map.fitBounds(bounds);
     searchBox.set('map', map);
     map.setZoom(Math.min(map.getZoom(),12));

   });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.