How do I assign the value of my variable place
to be the value of my variable address? So I can bind the value. They are NOT in the same script tag. When I console.log my variable place
I can see the address, but I have no idea on how to set the value for my variable address
.
<script>
let address = "";
</script>
They are **NOT **in the same script tag.
<div class="address">
<label for="">Address: </label> <br />
<script
src="https://maps.googleapis.fsdfsdfcom/maps/api/js?key=s&libraries=places"
></script>
<input
id="autocomplete"
placeholder="address"
type="text"
bind:value={address}
/>
<br />
<script>
let autocomplete = new google.maps.places.Autocomplete(
document.getElementById("autocomplete"),
{
componentRestrictions: { country: "au" },
}
);
autocomplete.addListener("place_changed", () => {
var place = autocomplete.getPlace().formatted_address;
});
</script>
</div>
I want to get my value of my variable place
in the addListener
and use the value for the address variable, so I can fetch my data. Everything I tried didn’t work. I want to use the value returned from my GoogleAPI, which I can see when I console.log my variable var, to my variable address, which is NOT in the same script tag. I tried to use the variable “`address“ with global scope, but it didn’t work or I didn’t do it correctly. Also I tried to do that, and it didnt work.
I need to be able to use the variable place
out of the script tag or anything that allows me to use that to assign its value to address. This is SvelteKit
Att.