I wanted to use the google address search but also wanted to introduce some personal areas.
In div
that is generated by google I can add the fields I want, but I can not create a function in click
because there must be something in google api that blocks click
.
Here is the code I used to add to the search:
$(".pac-container").append('<div id="areasearch' + e + '" class="pac-item areasearch" style="display:none" onclick="clickOneAreaLocalizar(\'' + $(this).text() + '\')"><span class="pac-icon pac-icon-areas"></span><span class="pac-item-query"><span class="pac-matched"></span>' + $(this).text() + '</span> <span>Area</span></div>');
Result:
Hereisthecodetoaddthesearchtotheinput:
varinput=/**@type{HTMLInputElement}*/(document.getElementById('TextBoxPesquisaMaps'));varsearchBox=newgoogle.maps.places.Autocomplete(/**@type{HTMLInputElement}*/(input),{types:['geocode']});//Listenfortheeventfiredwhentheuserselectsanitemfromthe//picklist.Retrievethematchingplacesforthatitem.google.maps.event.addListener(searchBox,'place_changed',function(){varplaces=searchBox.getPlace();//Foreachplace,gettheicon,placename,andlocation.varbounds=newgoogle.maps.LatLngBounds();bounds.extend(places.geometry.location);localizarMaisProximo(places.geometry.location);map.fitBounds(bounds);});
Imadethisexampletounderstandbetter. jsfiddle when you load qwerty it makes an alert.
Does anyone have any idea how to do this? Thank you.