I am trying to make a simple iframe in my react component that will show a google map location. I am currently hard-coding the src like this
this.state.features.map(function(school){
return(
<div>
{school.name}
<div>
<iframe frameBorder="0" style={{ width: "100%", height: "450"}}
src="https://www.google.com/maps/embed/v1/place?q=40.7127837,-74.0059413&key=AIzaSyCc3zoz5TZaG3w2oF7IeR-fhxNXi8uywNk">
</iframe>
</div>
</div>
)
})
which seems to work. However I want to pass the scr using a react variable so I am doing something like this
const MY_API = AIzaSyCc3zoz5TZaG3w2oF7IeR-fhxNXi8uywNk
let _url = "https://www.google.com/maps/embed/v1/place?q=40.7127837,-74.0059413&key="+MY_API;
and then passing the src dynamically like this
<iframe frameBorder="0" style={{ width: "100%", height: "450"}}
src={_url}>
</iframe>
but now I get the following error
The Google Maps API server rejected your request. Invalid request. Unexpected parameter 'amp%3Bkey'
Not sure what's the error message is about. help please.
Try this (I am unable to comment on questions yet)
const MY_API = 'AIzaSyCc3zoz5TZaG3w2oF7IeR-fhxNXi8uywNk'
let _url = `https://www.google.com/maps/embed/v1/place?key=${MY_API}&q=40.7127837,-74.0059413`
The above is using ES6 template literals
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With