Global Variable Not Working Fully
Briefly

The issue you are facing likely arises from variable scope in JavaScript. Variables defined inside a function are local to that function and cannot be accessed outside of it. If you require the latitude and longitude variables to be accessed globally, you should define these variables outside of the function and then update their values within the function.
For instance, instead of declaring 'latitude' and 'longitude' within the function, you could declare them at the top of your script. This way, their values can be retained and accessed from anywhere in your script after the function executes.
If initialized outside the function, make sure to assign the new values to these variables correctly within your Google Map click event handler so that their updated values persist.
Remember that asynchronous operations in JavaScript may also affect variable values. If your map events are not triggered correctly, or if they occur after other code tries to access the variables, you might be trying to read the variables before they are updated.
Read at SitePoint Forums | Web Development & Design Community
[
|
]