I need to know where to put my Google Map API Key in Magento 1.9.4.5 to prevent wrong inputs in address bar. I think it is straight forward in Mgento 2 but I can not find anywhere in Magento 1.9.4.5! Now the address input bar accept wrong addresses and I need to integrate the Google API to prevent this matter. Thank you for your help.
1 Answer
Magento 1.9 does not have a built-in way to set up a Google Maps API key. However, it is possible to integrate Google Map API in Magento 1.9.4.5. Generally, it involves the following steps:
Obtain a Google Maps API Key
Go to the Google Cloud Console. Create or select a project. Click on "Enable APIs and Services". Search for "Geocoding API" and enable it. Do the same for "Maps JavaScript API" and "Places API". Go to the "Credentials" tab on the left side and click on "Create Credentials". Follow the steps to create the API key. Note down the API Key. Create a Custom Module
You would need to create a custom module for this. The module will typically have a system.xml file where you can add fields to Magento's configuration. Here, you can add a field to save the Google Maps API Key:
<google translate="label" module="namespace_module">
<label>Google</label>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<api_key translate="label">
<label>Google Maps API Key</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[Enter your Google Maps API Key here.]]></comment>
</api_key>
</fields>
</google>
Once this module is created and installed correctly, you can access the Magento admin panel, and navigate to System > Configuration. In the Configuration panel on the left, you will find a section for the Google Map API Key.
Edit the Address Field
After saving the API Key in your Magento backend, you should now modify the address field where you want to implement the Google API feature.
You will need to write JavaScript (in your module or directly in template files that are responsible for the address fields) to access the Google APIs. Here is a brief overview of the steps you might take:
Use JavaScript to listen for input changes in your address field. When the address field changes, send a request to the Google API with the user's input and your API key. Google will return a response that you can use to auto-complete the user's input or validate that the address is correct.