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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:54:37+00:00 2026-06-11T10:54:37+00:00

As i am working on object oriented javascript, i have created one map object

  • 0

As i am working on object oriented javascript, i have created one map object and as i need to maintain the all previous routes and markers i am not creating new Map object. My code is as follows

function map() {

    this.defaultMapOption   =    {
        center : new google.maps.LatLng(0, 0),
        zoom : 1,
        mapTypeId : google.maps.MapTypeId.ROADMAP
    };

    this.map    =   null;

    this.marker =   [];

    this.directionsDisplay = null;
}

map.prototype.init = function() {


    this.map    =   new google.maps.Map(document.getElementById("map"), this.defaultMapOption);

    var map1    =   this.map;
    var marker1 =   this.marker;

    var count   =   0;

    google.maps.event.addListener(this.map, 'click', function(event) {

        count++;

        $(".tabNavigation li").find("a[href=markers]").trigger('click');

        if ( marker1[count] ) {
            marker1[count].setPosition(event.latLng);
        }
        else
        {
            marker1[count] = new google.maps.Marker({
                position: event.latLng,
                map: map1,
                draggable : true
            });

            //by clicking double click on marker, marker must be removed.
            google.maps.event.addListener(map.marker[count], "dblclick", function() {

                console.log(map.marker);

                map.marker[count].setMap(null);//this was working previously
                map.marker[count].setVisible(false);//added this today

                $("#markers ul li[rel='"+count+"']").remove();

            });

            google.maps.event.addListener(marker1[count], "dragend", function(innerEvent) {
                var geocoder = new google.maps.Geocoder();

                geocoder.geocode({'latLng': innerEvent.latLng}, function(results, status) {

                    if (status == google.maps.GeocoderStatus.OK) {
                        map.addMarkerData(results, count);
                    }
                    else
                    {
                        alert("Geocoder failed due to: " + status);
                    }
                });
            }); 

            var geocoder = new google.maps.Geocoder();

            geocoder.geocode({'latLng': event.latLng}, function(results, status) {

                if (status == google.maps.GeocoderStatus.OK) {

                    map.addMarkerData(results, count);
                }
                else
                {
                    alert("Geocoder failed due to: " + status);
                }
            });
        }
    });

}

Only above code works for only one marker. Means first time marker get removed on double click. After that it wont work.

Any ideas that why its stopped working!

  • 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-11T10:54:38+00:00Added an answer on June 11, 2026 at 10:54 am

    Your count value is incrementing with new markers and in addListener(map.marker[count],...) , count will contain the latest value. So only that marker will be deleted.

    So you should be decrementing the count value at the end in the addListener function.

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

Sidebar

Related Questions

I have been working on keeping things object oriented for my project. Currently, I'm
I'm working on my first object oriented bit of python and I have the
I'm working on a java object oriented expression tree assignment where I need to
I'm working on a project in C#. The previous programmer didn't know object oriented
I'm working on an object-oriented Excel add-in to retrieve information from our ERP system's
I have some working Javascript that manipulates the some DOM elements. The problem is,
I'm working through this tutorial: http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-3.php At first he has you create a setter
So I'm working on familiarizing myself with object oriented programming by messing around with
me and my buddy are working on a program for our Object Oriented Programming
I became a professional programmer in the era of object oriented code, and have

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.