Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:54:58+00:00 2026-05-27T09:54:58+00:00

I’ve managed to add markers to a Google Map on click, but now I

  • 0

I’ve managed to add markers to a Google Map on click, but now I need to update an <input> field inside a form each time a new marker is placed. So, when a new marker is placed, the input in question is updated with the latitude and longitude of the marker.

I’m using Google Maps Javascript API v3.

Here’s my Javascript:

<script type="text/javascript">
function load() {
    var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(39.47860556892209,-3.328857421875),
        zoom: 7,
        mapTypeId: 'roadmap'
    });

    var infoWindow = new google.maps.InfoWindow;
    google.maps.event.addListener(map, 'click', function(event) {
        //NEITHER OF THESE 2 OPTIONS WORK
        cambiarMarker(event.latLng);
        //document.getElementById("lat").value = event.latLng.lat();
        //document.getElementById("lng").value = levent.latLng.lng();
        document.forms['insertData'].lati.value = location.lat();
        document.forms['insertData'].long.value = location.lng();   
    });

    var markerActual;

    function cambiarMarker(location) {
        //CREATES AND PUT THE NEW MARKER
    }

    downloadUrl("phpsqlajax_genxml2.php", function(data) {
        //GETS INFO FROM AN XML THAT IS CREATED FROM THE DATABASE WITH PHP 
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
        //BINDS INFORMATION WINDOW WITH THE XML INFO
    }


    function downloadUrl(url, callback) {
        //GET THE XML FILE
    }

    function parseXml(str) {
        //PARSES FROM THE XML
    }

    function doNothing() {}
</script>

And here’s my HTML:

<body onload="load()">
    Aqui debería salir algo
    <div id="map" style="width: 500px; height: 300px"></div>
    <form name="insertData" action="insertar_datos.php" method="post">
        Nombre: <input type="text" name="name"><br>
        Dirección: <input type="text" name="address"><br>
        Latitud: <input type="text" name="lati" id="lat"><br> <!--HERE'S INPUT1-LATITUDE-->
        Longitud: <input type="text" name="long" id="lng"><br> <!--HERE'S INPUT2-LONG-->
        Teléfono de contacto: <input type="text" name="telefono"><br>
        Comentario: <textarea name="comentario"></textarea><br>
        <input type="submit" value="Enviar">
    </form>
</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:54:58+00:00Added an answer on May 27, 2026 at 9:54 am

    In principle you could also handle change event on the input field and set the coordinates of the marker. This is what I’m doing in my application. And also I handle the drag event of a marker and change the coordinates during dragging. In this case handle both drag and dragend events of a marker! The dragend you MUST handle, the drag not so but it is cool to let the coordinates change as you drag the marker 🙂

    The change event of input field can be handled e.g. this way (using jquery, supposing markup like <input id="coords"...):

    $('input#coords').change(function () {
        // do the job here: 
        // - convert field coordinates to latLng
        //   for reading the field value use $('input#coords').val()
        // - set the marker position to the new one
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.