vbernal
vbernal

Reputation: 723

How to get the latitude and longitude value when the user marks a point on the map?

I'm still a beginner in React, and I'm doing a test project where the user marks a point on the map. The problem is that I am not able to save the value of the latitude and longitude variables. I need the value of these variables to send in a form later.

enter image description here

As you can see, in console.log() you can see what the latitude and longitude is. What I need is to save this value in a variable to send later.

Here's the code I'm working on StackBlitz: https://stackblitz.com/edit/react-mdhsxj?file=MapContainer.js

Can someone help me? Thank you in advance.

Upvotes: 1

Views: 331

Answers (1)

artoonie
artoonie

Reputation: 847

What do you mean by "Later"? Later in the same page load? Later as in another day? For another user?

If you mean, "later in another page load," you need to consider long-term storage options (search for "Web Storage").

If you mean "for another user," you need to look into a database.

If you just want to use it in later in the page load, just do something like:

var latitude = data.latitude;
var longitude = data.longitude;
// ...later
console.log(latitude)
console.log(longitude)

and you can use it "later".

Upvotes: 0

Related Questions