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

  • Home
  • SEARCH
  • 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 6006951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:36:46+00:00 2026-05-23T01:36:46+00:00

I wonder whether someone may be able to help me please. I’ve put some

  • 0

I wonder whether someone may be able to help me please.

I’ve put some coding together (please see below) whereby a user goes onto a HTML form, they type in an address and click a ‘Search’ button. Upon doing this, the location is plotted on the Google map and the Lat and Long co-oridnates are automatically entered into the associated text boxes on my form.

What I would like to do, if at all possible, is for the marker to be draggable so the user can fine tune the location, and as they drag the marker, I’d like for the Lat and Long fields to change their
associated co-ordinates.

In addition, I’d also like, if at all possible, to have a field on the form called ‘NearestAddress’ to show the nearest address to where the marker has been dragged to.

I’ve managed to make the markers draggable but they don’t update the Latitude and Longitude text boxes. I’m also unsure how to add the functionality to show the updated address to where the marker has been dragged to.

(function() {
// Defining some global variables
var map, geocoder, myMarker, infowindow;
window.onload = function() {
// Creating a new map
var options = {
zoom: 3,
center: new google.maps.LatLng(55.378051,-3.435973),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
// Getting a reference to the HTML form
var form = document.getElementById('LocationSearchForm');
// Catching the forms submit event
form.onsubmit = function() {
// Getting the address from the text input
var address = document.getElementById('Address').value;
// Making the Geocoder call
getCoordinates(address);
// Preventing the form from doing a page submit
return false;
}
}
// Create a function the will return the coordinates for the address
function getCoordinates(address) {
// Check to see if we already have a geocoded object. If not we create one
if(!geocoder) {
geocoder = new google.maps.Geocoder();
}
// Creating a GeocoderRequest object
var geocoderRequest = {
address: address
}
// Making the Geocode request
geocoder.geocode(geocoderRequest, function(results, status) {
// Check if status is OK before proceeding
if (status == google.maps.GeocoderStatus.OK) {
// Center the map on the returned location
map.setCenter(results[0].geometry.location);
    // Creating a new marker and adding it to the map
        var myMarker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location,
            draggable:true
        });

        document.getElementById('Latitude').value=  results[0].geometry.location.lat();
        document.getElementById('Longitude').value=  results[0].geometry.location.lng();

        google.maps.event.addListener(myMarker, 'dragend', function(evt){
        document.getElementById('current').innerHTML = '<p>Marker dropped: Current Lat: ' + evt.latLng.lat().toFixed(3) + ' Current Lng: ' + evt.latLng.lng().toFixed(3) + '</p>';
        });

        google.maps.event.addListener(myMarker, 'dragstart', function(evt){
        document.getElementById('current').innerHTML = '<p>Currently dragging marker...</p>';
        });

        map.setCenter(myMarker.position);
        myMarker.setMap(map);

      } 

    });

  }

})();

I am new to Google maps development and I’m not even sure whether it’s possible to achieve what I want. I’ve been working on this now for a few weeks and it’s driving me a little crazy, so if someone could perhaps point me in the right direction it would gratefully be received.

Many thanks and kind regards

Chris

  • 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-23T01:36:47+00:00Added an answer on May 23, 2026 at 1:36 am

    Instead of evt.latLng.lat().toFixed(3) you should just use the myMarker object and grab it’s position.

    Getting the nearest address is not that easy, but requires reverse geocoding, and to be honest I don’t see the point in doing it. You would have to make special cases for the occurences where there couldn’t be found a closest address and stuff like that.

    If you really want to do it though there is a webservice you can call to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

wonder whether someone can help me with the following one... I have a struct
I wonder whether there is any automatic way of determining (at least roughly) the
I just wonder a bit whether or not GDI+ is still a technology worth
I wonder, whether it is possible to create class-methods in VBA. By class-method I
I wonder if someone knows if there is a pre-made solution for this: I
I wonder if They can work perfectly together...
I wonder whether MATLAB is Turing complete (= computationally universal, i.e. if it can
I wonder whether it is possible to find what is the encoding of string?
I'm new to mobile phones development, but I wonder whether there is any way
I wonder whether BDD is a replacement of TDD ? What I understand now

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.