0

HTML code

<div id="formulario">
    <h1>Posicionamento de CEO</h1>
    <form method="POST" style="width: 500px;">   

<div class="form-group">
   <label class="control-label  " for="id_identification">Identificação</label>
        
<div class=" ">enter code here
   <input type="text" name="identification" maxlength="256" class=" form-control" required="" id="id_identification">
</div>
</div>
<div class="form-group">
   <label class="control-label  " for="id_geolocation">Geolocalização</label>
       <div class=" ">
            <input type="text" name="geolocation" maxlength="100" class=" form-control" required="" id="id_geolocation">
</div
        <button type="button" onclick="start()" class="botao">Clique aqui para carregar 
         mapa</button>
    </form>
</div>

Javascript code that opens the map and captures the coordinate when I click on the map.

async function sendCoordsToMyApi(evt) {
    const coords = {
      lat: evt.latLng.lat(),
      lng: evt.latLng.lng()
    };

    console.log("vou enviar as coordenadas para api:", coords);
    alert(JSON.stringify(coords));

I need to enter the coordinate of the constant coords in the form in the input field id="id_geolocation" can you help me?

1
  • I’m voting to close this question because so is english only Commented Mar 7, 2022 at 1:33

1 Answer 1

1

You can use document.getElementById to get the element you are trying to add text to

coords = ...;
document.getElementById("id_geolocation").value = JSON.stringify(coords);
Sign up to request clarification or add additional context in comments.

2 Comments

@RaphaelMaia if the answer works, you should select it as the answer to your question.
@RaphaelMaia To select, click the check mark next to the number score of the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.