SOLVED

Re: Embed Code Not working with Google places API

Go to solution
Ravi_Ansal2
Level 6

Embed Code Not working with Google places API

Hi,

I have created a Code to auto complete the Company name using Google Location.

Refer Below but it is not working can you help me with the issue:

<script src="//app-sj04.marketo.com/js/forms2/js/forms2.min.js"></script>

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

<form id="mktoForm_1627"></form>

<script>

MktoForms2.loadForm("//app-sj04.marketo.com", "023-STC-548", 1627,

function(form)

{

    var formEl = form.getFormElem()[0];

    var companyField = formEl.querySelector('INPUT[name="Company Name"]');

 

    var defaultBounds = new google.maps.LatLngBounds(

      new google.maps.LatLng(-90,-180),

      new google.maps.LatLng(90,180)

    );

   

    var options = {

        bounds: defaultBounds,

        types: ['establishment']

    };

    autocomplete = new google.maps.places.Autocomplete(companyField, options);

   

    google.maps.event.addListener(autocomplete, 'place_changed', function() {

        // shorten object to just name

        acCompanyName = autocomplete.getPlace().name;

        companyField.value = acCompanyName;   

       

        // just for fun, fill website too

        acWebsite = autocomplete.getPlace().website;

        if (acWebsite) websiteField.value = acWebsite;  

  });   

});       

</script>

and also what is difference between Field and name in Marketo?

Message was edited by: Ravi Ansal

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Embed Code Not working with Google places API

Those are additional fields on the autocomplete object.  MktoForms2 :: Google Places Autocomplete is updated to show how to retrieve those values, at least for US addresses.  You can do whatever you want with the values.

View solution in original post

9 REPLIES 9
John_M
Marketo Employee

Re: Embed Code Not working with Google places API

Ravi

In order to do something when the form loads, you would use the "loadForm" function in the Forms 2.0 API. Check out the forms 2.0 Documentation, Examples and API.

MktoForms2.loadForm("//app-pod.marketo.com", "123-xxx-567", 1057, function(form) {

  // Call your code here to populate the company field

});

Ravi_Ansal2
Level 6

Re: Embed Code Not working with Google places API

Hi John Mattos​,

I think i am doing it right. But the value on the field is not populating.

Can you help me with that.

SanfordWhiteman
Level 10 - Community Moderator

Re: Embed Code Not working with Google places API

Ravi, it appears you are using my code from MktoForms2 :: Google Places Autocomplete (you really should attribute it instead of saying you "created a code").

Obviously the demo works, so there is something wrong with how you're plugging it in.  Please provide your actual URL so we can see.

Re: "difference between field and name," every Marketo field has an "API name" which is the name you'll see if you inspect the form field and thus the name we always work with on the browser side.

Ravi_Ansal2
Level 6

Re: Embed Code Not working with Google places API

Hi Sanford Whiteman​,

I did not know that it was your code, Thank you very much for this.

it worked for me as well . But just one more question, Can I get the full address, city and state and though in Hidden fields.

And again Thanks a Ton. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Embed Code Not working with Google places API

Those are additional fields on the autocomplete object.  MktoForms2 :: Google Places Autocomplete is updated to show how to retrieve those values, at least for US addresses.  You can do whatever you want with the values.

kellyej
Level 1

Re: Embed Code Not working with Google places API

Hello, Ive seen this link under several of your responses to questions surrounding this topic, but the url does not work.

SanfordWhiteman
Level 10 - Community Moderator

Re: Embed Code Not working with Google places API

Looks fine to me:

SanfordWhiteman_0-1644960113767.png

 

kellyej
Level 1

Re: Embed Code Not working with Google places API

Thanks so much for your response. For some reason, there is a 404 error (even when I am logged into my codepen account). But thank you for including the screenshot of the code in use, I can use that!

404 codepen.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Embed Code Not working with Google places API