Home › Forums › General Issues › How to retrieve only iframe source link of Google Map Custom Field.
I display in one page the Google map but in the footer only the link to the google map. If possible I would like to use the easier to use google map custom fields for both: to retrieve the map (which is in the docs and is working great) and also the iframe source link.
The google map iframe link looks like the following:
src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=ADDRESS"
https://developers.google.com/maps/documentation/embed/guide
So, you can try:
<?php
$map = get_field('the_map_field');
$src = esc_url(add_query_arg([
'key' => YOUR_API_KEY,
'q' => $map['address']
], 'https://www.google.com/maps/embed/v1/place'));
?>
<iframe
width="600"
height="450"
frameborder="0" style="border:0"
src="<?php echo $src; ?>" allowfullscreen>
</iframe>
Cheers
I’m getting this error “The Google Maps API server rejected your request. Invalid request. Missing the ‘q’ parameter.”
There seemed to be a missing “)” tried many combinations though I’m not sure I included it correctly..
$src = esc_url(add_query_arg([
'key' => MyKey,
'q' => $map['address']], 'https://www.google.com/maps/embed/v1/place')); ?>
Regards.
Oop, my bad, yeah i did missed a ‘)’. I’ve edited to the correct code.
Can you double check the url that it’s generated? (do a var_dump($src);
before your iframe).
Can you also make sure the proper map services are enabled on that key? It doesn’t say in the google’s documentation, but i think you might also need to enable the “Google Places API Web Service” in order to use the place search.
Cheers
I mistaked as well in the beginning it returned the api error but later it returned that the q parameter is missing though it was included in the code. I’m sorry about that I edited the above post as well.
Ok the dump returned
string(48) “https://www.google.com/maps/embed/v1/place?key=0”
Can you also make sure the proper map services are enabled on that key? It doesn’t say in the google’s documentation, but i think you might also need to enable the “Google Places API Web Service” in order to use the place search.
Ok checking it…
Based on that dump url, seems like your $map[‘location’] is false, therefore the ‘q’ parameter is not being added.
Also weird that your key is 0. How did you defined your MyKey
?
try do a var_dump($map)
and see if acf actually returns any value.
I just tried it too, the code seems to work for me.
Cheers
Mmm that’s odd. The var_dump($map); returns”bool(false)”
In case I’m doing a foolish error:
Regards.
Usually when it return false is because there’s no value set on the post.
Can you double check that
1) your Map Field’s name is indeed called ‘google_map’?
2) the value is also saved properly?
3) your current post is indeed the post your are retrieving the value from? (do a var_dump(get_the_ID())
and see if the current post id is the same post id where you put the acf field)
4) make sure you are not mis-using get_field
and get_sub_field
(we all make this mistake form time to time 😉 )
Cheers
1) Checked..
2) and 3) I’m testing it in the same loop the regular acf google map is.
4) Checked that.
Did some changes and it no longer returns the initial error but this one:
“The Google Maps API server rejected your request. This API project is not authorized to use this API.”
So maybe is as you pointed earlier the api “Google Places API Web Service” is needed in addition.
The topic ‘How to retrieve only iframe source link of Google Map Custom Field.’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.