Using google search address, Using two times in application, on every page load , it works fine second time does not work properly sometimes second time works


$("#autocomplete").on('focus', function () {

var placeSearch, autocomplete;
var componentForm = {
    street_number: 'short_name',
    route: 'long_name',
    locality: 'long_name',
    administrative_area_level_1: 'short_name',
    country: 'long_name',
    postal_code: 'short_name'

function initialize() {
    autocomplete = new google.maps.places.Autocomplete(
    /** @type {HTMLInputElement} */ (document.getElementById('autocomplete')), {
        types: ['geocode']
    google.maps.event.addListener(autocomplete, 'place_changed', function () {

function fillInAddress() {
    var place = autocomplete.getPlace();

    document.getElementById("latitude").value =;
    document.getElementById("longitude").value = place.geometry.location.lng();

    for (var component in componentForm) {
        document.getElementById(component).value = '';
        document.getElementById(component).disabled = false;

    for (var i = 0; i < place.address_components.length; i++) {
        var addressType = place.address_components[i].types[0];
        if (componentForm[addressType]) {
            var val = place.address_components[i][componentForm[addressType]];
            document.getElementById(addressType).value = val;

function geolocate() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (position) {
            var geolocation = new google.maps.LatLng(
            position.coords.latitude, position.coords.longitude);

            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
            document.getElementById("latitude").value = latitude;
            document.getElementById("longitude").value = longitude;

            autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation));


<script src = ""
async defer> </script>

I strongly recommend reading the Meteor Guide. Embedding <script> tags in HTML is not the correct way to write a Meteor app, or any app which has dynamically rendered DOM elements. It most likely will not work, or will work intermittently.

1 Like

After a string of questions like this which show a complete misunderstanding of Meteor and no replies to people asking for more information so they can help you, I’m starting to suspect that you’re a bot.

If you’re not, I’d suggest going through the tutorial:

Reading the meteor guide:

And actually engaging with the people that want to help you on the forums!
These hit and run questions are quite frustrating

1 Like