Is there a way to assign the value of my variable place
to my variable address, even though they are not in the same script tag? I want to bind the value and utilize it for fetching data. When I log my variable place
, I can see the address, but I am unsure of how to set this 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 need to retrieve the value of my variable place
from the addListener
function and use that value to update the address variable so I can fetch the necessary data. Despite trying various methods, I have been unsuccessful. I attempted using the global scope for the address
variable without success.
I'm looking for a solution that allows me to use the value of place
outside of the script tag to assign it to my address variable. This is within the context of SvelteKit.
Kind regards,
EDIT:
https://i.sstatic.net/rQTis.png
EDIT2: