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 8598503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:09:56+00:00 2026-06-12T01:09:56+00:00

How, when geocoding, can you simply move an existing marker to the result of

  • 0

How, when geocoding, can you simply move an existing marker to the result of a new geocode result.

Let’s take this example:

  • When the map loads, a marker appears
  • When someone geocodes, the marker moves to the result
  • The marker is draggable, so the user can further move the marker (if they want to)
  • Perhaps they want to re-geocode a location, so the new result should automatically move the existing marker.

In this sample:

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

…a new marker is drawn for every new geocode.

Does that make sense?

Thanks!!!

-m

  • 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-06-12T01:09:57+00:00Added an answer on June 12, 2026 at 1:09 am
    1. Make the marker global.
    2. Check if it exists before creating a new one.
    3. if it exists use .setPosition to move it to the new location
    4. if it doesn’t exist, create a marker at the desired location.

    Example that does something close to what you want

    working code snippet:

    var map = null;
    var marker = null;
    var geocoder = new google.maps.Geocoder();
    var infowindow = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0,-34)});
    
    function initialize() {
      map = new google.maps.Map(document.getElementById('map-canvas'), {
        center: new google.maps.LatLng(42, -85),
        zoom: 4
      });
    }
    
    function codeAddress() {
      var address = document.getElementById('address').value;
      geocoder.geocode({
        'address': address
      }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          content = results[0].formatted_address;
          infowindow.setContent(content);
          if (marker && marker.setPosition) {
            marker.setPosition(results[0].geometry.location);
          } else {
            marker = new google.maps.Marker({
              map: map,
              icon: {
                url: 'http://maps.google.com/mapfiles/arrow.png',
                anchor: new google.maps.Point(10, 34)
              },
              position: results[0].geometry.location
            });
            google.maps.event.addListener(marker, 'click', function(evt) {
              infowindow.open(map);
            });
          }
          infowindow.setPosition(results[0].geometry.location);
          infowindow.open(map);
        } else {
          alert('Your search was not successful for the following reason: ' + status);
        }
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    html,
    body,
    #map-canvas {
      height: 500px;
      width: 500px;
      margin: 0px;
      padding: 0px
    }
    <script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
    <input id="address" value="New York, NY" />
    <input id="geocode" type="button" value="Find" onclick="codeAddress()" />
    <div id="map-canvas"></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to Google Map's Geocode API documentation: https://developers.google.com/maps/documentation/geocoding/index#GeocodingRequests you can simply make a call
I have found this code for reverse geocoding: var point = new GLatLng (lat[1],long[1]);
I'm trying to modify existing perl script to support geocoding. Found this module for
I want to display the marker on the map but I can see only
Can I use the reverse geocoding server side, e.g. with a C# or C++?
Ideally something I can plug and play pretty readily an quickly that supports GeoCoding
I'm working with google maps geocoding service in order to geocode some addresses and
Where can i find a free service for reverse geocoding a coordinate in israel
Google Terms says I can only use reverse geocoding in conjunction with a google
I have a requirement to geocode data using Google's geocoding service. Google's geocoding services

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.