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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:57:31+00:00 2026-06-11T08:57:31+00:00

I created two custom buttons on Google Maps to create markers When I click

  • 0

I created two custom buttons on Google Maps to create markers
When I click on button 1 it create a marker with one icon, and when I click on button 2 it create a button with another icon, but when I click first in a button, create the marker then in another button, and create the another marker, it create the 2 buttons, one in front of the other. I dont know why, this is my code:

This is my example

var map, ren, ser;

var marker;
var infowindow;
var doMark = false ;
var doMark2 = false;



//Função de Inicio

function goma()
{
    if (doMark == 0)
    {
        doNothing();
    }
    var mapDiv = document.getElementById('mappy');

    var mapOptions = {
    zoom: 12, 

    center: new google.maps.LatLng(-23.563594, -46.654239),
    mapTypeId : google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map( mapDiv, mapOptions );


    var teste = document.createElement('DIV');
    teste.style.padding = '1px';
    teste.style.border = '1px solid #000';
    teste.style.backgroundColor = 'white';
    teste.style.cursor = 'pointer';
    teste.innerHTML = '<img src="http://i47.tinypic.com/2dlp2fc.jpg" border="0" alt="Image and video hosting by TinyPic">';
    teste.index = 1;


    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(teste);

        var rest = document.createElement('DIV2');
    rest.style.padding = '1px';
    rest.style.border = '1px solid #000';
    rest.style.backgroundColor = 'white';
    rest.style.cursor = 'pointer';
    rest.innerHTML = '<img src="http://i45.tinypic.com/2yua8ns.png" border="0">';
    rest.index = 1;
    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(rest);

    google.maps.event.addDomListener(teste, 'click', function() 
    {
        doMark = true;
        doMark2 = false;
        markNow();
    });
    google.maps.event.addDomListener(rest, 'click', function() 
    {

        doMark = false;
        doMark2 = true;
        markNow2();
    });

}   

var string = JSON.stringify(data2)

function downloadUrl(url, callback) 
{
    var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    request.open('POST',url);
    request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    request.send('command=save&marker='+string)
    request.onreadystatechange = function()
    { 
        if(request.readyState==4) 
        {
            if(request.responseText.indexOf('bien')+1)
            {
                alert('Mapa Atualizado !');
            }
            else
            {
                alert(request.responseText);
            }
        }
    }
}

function markNow()
{
    //doMark2 = true;
    if (doMark == true)
    {

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

            marker = new google.maps.Marker({ position: event.latLng, map: map});
            if (doMark ==1)
            google.maps.event.addListener(marker, "click", function() 
            {
                infowindow.open(map, marker);
            });
        });
        var html = "<table>" +
           "<tr><td>Nome:</td> <td><input type='text' id='name'/> </td> </tr>" +
           "<tr><td>Endereco:</td> <td><input type='text' id='address'/></td> </tr>" +
           "<tr><td>Tipo:</td> <td><select id='type'>" +
           "<option value='oficina' SELECTED>oficina</option>" +
           "<option value='restaurante'>restaurante</option>" +
           "</select> </td></tr>" +
           "<tr><td></td><td><input type='button' value='Salvar' onclick='saveData()'/></td></tr>";

infowindow = new google.maps.InfoWindow({content: html});
    }
}

function markNow2()
{

    if (doMark2 == true)
    {

        google.maps.event.addListener(map, "click", function(event) 
        {
            doMark = 0
            marker = new google.maps.Marker({ position: event.latLng, map: map, icon: 'http://i45.tinypic.com/2yua8ns.png' });
            google.maps.event.addListener(marker, "click", function() 
            {
                infowindow.open(map, marker);
            });
        });
        var html = "<table>" +
           "<tr><td>Nome:</td> <td><input type='text' id='name'/> </td> </tr>" +
           "<tr><td>Endereco:</td> <td><input type='text' id='address'/></td> </tr>" +
           "<tr><td>Tipo:</td> <td><select id='type'>" +
           "<option value='oficina' SELECTED>restaurante</option>" +
           "<option value='restaurante'>oficina</option>" +
           "</select> </td></tr>" +
           "<tr><td></td><td><input type='button' value='Salvar' onclick='saveData()'/></td></tr>";

infowindow = new google.maps.InfoWindow({content: html});
    }

}
  • 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-11T08:57:32+00:00Added an answer on June 11, 2026 at 8:57 am

    You have 2 functions markNow() and markNow2() which together create one marker on top of the other.
    In markNow() the marker should be chosen within the function.The rest of the code is equivalent in both functions.

    Delete markNow2() and change markNow() to

    function markNow(){   
    
        google.maps.event.addListener(map, "click", function(event) 
        {
            if (doMark == true){
            alert("Marker 1 Chosen");
            marker = new google.maps.Marker({ position: event.latLng, map: map});
            }
            if (doMark2 == true){
            alert("Marker 2 Chosen");
            marker = new google.maps.Marker({ position: event.latLng, map: map, icon: 'http://i45.tinypic.com/2yua8ns.png' });
            }
            //if (doMark ==1)
            google.maps.event.addListener(marker, "click", function() 
            {
                infowindow.open(map, marker);
            }
            );
        }
        );
        var html = "<table>" +
           "<tr><td>Nome:</td> <td><input type='text' id='name'/> </td> </tr>" +
           "<tr><td>Endereco:</td> <td><input type='text' id='address'/></td> </tr>" +
           "<tr><td>Tipo:</td> <td><select id='type'>" +
           "<option value='oficina' SELECTED>oficina</option>" +
           "<option value='restaurante'>restaurante</option>" +
           "</select> </td></tr>" +
           "<tr><td></td><td><input type='button' value='Salvar' onclick='saveData()'/>     </td></tr>";
    
      infowindow = new google.maps.InfoWindow({content: html});
    
    
    }
    

    This allows only 1 marker.

    In function goma()
    Change last from markNow2(); to markNow();

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

Sidebar

Related Questions

I have created a custom dialog, And I have inserted two buttons, one is
I've created a custom control which consists of two radio buttons with their appearance
I have created two custom controls. On the basis of features any one of
I'm trying to create a simple, custom, gallery. I have two lists, one with
I created two classes in netbeans;One of them is a JPanel form and another
I created two modules, one with def _func(): print hi and another def func():
I have created one gridview and use custom adapter for that. I added two
I want to create a custom View which contains two buttons without using xml.
I have created one gridview and use custom adapter for that. I added two
I created a Custom UITableCellView for my application. Each cell has two buttons. The

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.