bradcornford / Googlmapper

An easy way to integrate Google Maps with Laravel
MIT License
463 stars 143 forks source link

Auto Suggest Text Box #100

Open gezzeg opened 7 years ago

gezzeg commented 7 years ago

Hi,

I would like to create auto suggest base on what user key in on a search box.

But i dont know how to get the existing map and markers render by the package.

It seems i need to put the javascript inside the rendered code.

Is there any way i add an event listener inside the rendered code ?

Thank you.



var searchBox = new google.maps.places.SearchBox(document.getElementById('searchmap'));

google.maps.event.addListener(searchBox, 'places_changed', function () {
            var places = searchBox.getPlaces();
            var bounds = new google.maps.LatLngBounds();
            var i, place;
            for (i = 0; place = places[i]; i++) {
                bounds.extend(place.geometry.location);
                marker_0.setPosition(place.geometry.location);
            }
            map.fitBounds(bounds);
            map.setZoom(15);
        });
bradcornford commented 7 years ago

Hi there,

They are all accessible via a global 'maps' variable. You can access the current map using 'maps[0].map' and the markers using 'maps[0].markers'.

You can also use an after event to tie any custom javascript to the current map instance as folows:

Mapper::map(53.381128999999990000, -1.470085000000040000, ['eventAfterLoad' => 'console.log("after load");']);