Search code examples
wordpressgoogle-mapsgoogle-places-apiadvanced-custom-fieldsacfpro

How to authorize google location lookup acf field in wordpress when you have api's enabled and key provided - still throws ApiTargetBlockedMapError


Just trying to use the advanced custom fields wp plugin google location lookup field in post meta in the wordpress post editor backend.

No matter what I do the lookup always fails and says unauthorized. I have enabled all the api's for maps as seen bellow.

The key provided is the only one I have for the project, no restrictions and billing is enabled. I also verified the domain with this google console account by adding txt certificate to the DNS.

<?php 
    function my_acf_gmap_api( $api ){
    $api['key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    return $api;
} 
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

all the apis are enabled as seen here in this screenshot.

I can manually click on the map and set a location, the data is stored and displays perfectly on the front end. But I cant use the places lookup search which is the only way this field will be useful. This is the error that shows.

backend.js:6 This API key is not authorized to use this service or API. Places API error: 
ApiTargetBlockedMapError

this is the error console when trying to use lookup places.


Solution

  • Having the error 'ApiTargetBlockedMapError' means that the Maps JavaScript API has not been authorized for the used API key. The reason why you have this was because you have not included the Maps JavaScript API in the API restriction of your API key. That is why once you removed the restriction, it worked properly. For future reference to help you with troubleshooting your Google Maps Issues, here is a link that explains different Error Messages for Maps JavaScript API.