0

I am trying to add a googlemaps path to my requirejs-config file, but I need to put the locale on the end of the string. Here is what my requirejs-config file looks like. I need a way to get the local in javascript to put on the end of this url.

var config = {
    'map': {
        "*": {
            'googlemaps': '//maps.googleapis.com/maps/api/js?key=mykey&libraries=places&language=' + NEED-LOCAL-HERE
        }
    }
};

I would like to do this inside of //Magento_Checkout/web/template/shipping-address/form.html. This is what I have in that file right now.

<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form class="form form-shipping-address" id="co-shipping-form" data-bind="attr: {'data-hasrequired': $t('* Required Fields')}">
    <!-- ko foreach: getRegion('before-fields') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
    <!--/ko-->
    <div id="shipping-new-address-form" class="fieldset address">
        <!-- ko foreach: getRegion('additional-fieldsets') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!--/ko-->
        <!-- ko if: (isCustomerLoggedIn) -->
        <div class="field choice" data-bind="visible: !isFormInline">
            <input type="checkbox" class="checkbox" id="shipping-save-in-address-book" data-bind="checked: saveInAddressBook" />
            <label class="label" for="shipping-save-in-address-book">
                <span data-bind="i18n: 'Save in address book'"></span>
            </label>
        </div>
        <!-- /ko -->
    </div>
</form>

<script type="text/x-magento-init">
    {
        "*": {
            "shippingAddress": {
                "googlemapskey": "https//maps.googleapis.com/maps/api/js?key=mykey&libraries=places&language=PUT_LOCALE_HERE"
            }
        }
    }
</script>
4

You should pass the value in the template

In your .phtml template

require([
            "https//maps.googleapis.com/maps/api/js?key=mykey&libraries=places&language=<?php echo $block->getLanguageCode() ?>"
        ], function () {
            // Your code here
        });

You need to build the method getLanguageCode() in your block. You can pass your api key in template: key=mykey.

There are some extensions about google map. You can download and see the source code

https://github.com/mageplaza/magento-2-google-maps

https://amasty.com/google-map-for-magento-2.html

  • I am trying to do this inside of module-checkout/web/template/shipping-address.form.html, which I am overriding inside my design area. I will add more code above for what I am trying. – Metropolis Feb 21 at 16:57
  • I updated my code. – Metropolis Feb 21 at 19:02

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.