3

How can I implement Google Place Autocomplete at one of my custom text fields ?

  • In the salesforce UI or in visualforce ? – Samuel De Rycke Apr 8 '14 at 10:24
  • Basically in the UI, but both would be good to know. – David Renz Apr 8 '14 at 10:26
3

I found a way to do it in Visualforce:

<apex:page id="page">

    <script src="https://maps.googleapis.com/maps/api/js?language=de&sensor=false&libraries=places" type="text/javascript"></script>  
    <script type="text/javascript"> 

        function initializeField() {        
            var input = document.getElementById('page:form:pb:pbs:field');           
            var autocomplete = new google.maps.places.Autocomplete(input); 
        }

        google.maps.event.addDomListener(window, 'load', initializeField);  

    </script> 

    <apex:form id="form">
        <apex:pageBlock id="pb">
            <apex:pageBlockSection id="pbs">
                <apex:inputText id="field"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>   

</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.