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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:45:56+00:00 2026-06-14T13:45:56+00:00

I am new to JavaScript but this problem has been driving me crazy for

  • 0

I am new to JavaScript but this problem has been driving me crazy for two days and I cant find anyone with the same problem as mine.

I am trying to add a button to hide all of the markers on my map (eventually I want to make it so that I hide the markers by category, but hiding all markers for the moment will do) I am using the code from the Google developers website.

Here is my code

var map;
var service;
var infowindow;

function initialize() {
  var pyrmont = new google.maps.LatLng(49.2755189938682, -123.1185996613159);

  map = new google.maps.Map(document.getElementById('map'), {
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: pyrmont,
    zoom: 17
  });

  var request = {
    location: pyrmont,
    radius: '500',
    types: ['atm','bus_station','parking']
  };

  infowindow = new google.maps.InfoWindow();
  service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, callback);
  TestMarker();
}

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var place = results[i];
      createMarker(results[i]);
    }
  }
}

function TestMarker() {
       CentralPark = new google.maps.LatLng(49.2755189938682, -123.1185996613159);
       addMarker(CentralPark);
}

function addMarker(location) {
    marker = new google.maps.Marker({
        position: location,
        map: map,
        icon: "http://maps.google.com/mapfiles/ms/micons/POI.png",
        title: 'Sues Party, Idaburn Salon' 
    });
}

function createMarker(place) {

    var iconType = {};
    iconType['atm'] = "http://maps.google.com/mapfiles/ms/micons/dollar.png";
    iconType['bus_station'] =     "http://maps.google.com/mapfiles/ms/micons/bus.png";
    //iconType['restaurant'] = "http://maps.google.com/mapfiles/ms/micons/restaurant.png";
    iconType['parking'] = "http://maps.google.com/mapfiles/ms/micons/parkinglot.png";
    var placeLoc = place.geometry.location;
    var marker = new google.maps.Marker({
      map: map,
      icon: iconType[place.types[0]],
      position: place.geometry.location
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.setContent(place.name);
      infowindow.open(map, this);
    });
  }

  google.maps.event.addDomListener(window, 'load', initialize);

I have added a button to call a function, but I think the problem is getting the records from the array. Really stuck, any help is greatly appreciated. Even advice on what I need to be doing to get it to work

James

  • 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-14T13:45:58+00:00Added an answer on June 14, 2026 at 1:45 pm

    James. Try this code:

    <html>
      <head>
        <title></title>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&v=3&libraries=adsense,places"></script>
        <script type="text/javascript">
          var map;
          var service;
          var infowindow;
          var markers = [];
    
          function initialize() {
            var pyrmont = new google.maps.LatLng(49.2755189938682, -123.1185996613159);
    
            map = new google.maps.Map(document.getElementById('map'), {
              mapTypeId : google.maps.MapTypeId.ROADMAP,
              center : pyrmont,
              zoom : 17
            });
    
            var request = {
              location : pyrmont,
              radius : '500',
              types : ['atm', 'bus_station', 'parking']
            };
            infowindow = new google.maps.InfoWindow();
            service = new google.maps.places.PlacesService(map);
            service.nearbySearch(request, callback);
            TestMarker();
    
            var removeBtn = document.getElementById("removeBtn");
            google.maps.event.addDomListener(removeBtn, "click", onRemoveBtn_Clicked);
          }
    
          function onRemoveBtn_Clicked() {
            var i;
            for (i = 0; i < markers.length; i++) {
              markers[i].setMap(null);
            }
          }
    
          function callback(results, status) {
            if (status == google.maps.places.PlacesServiceStatus.OK) {
              for (var i = 0; i < results.length; i++) {
                var place = results[i];
                markers.push(createMarker(results[i]));
              }
            }
          }
    
          function TestMarker() {
            CentralPark = new google.maps.LatLng(49.2755189938682, -123.1185996613159);
            markers.push(addMarker(CentralPark));
          }
    
          function addMarker(location) {
            marker = new google.maps.Marker({
              position : location,
              map : map,
              icon : "http://maps.google.com/mapfiles/ms/micons/POI.png",
              title : 'Sues Party, Idaburn Salon'
            });
            return marker;
          }
    
          function createMarker(place) {
            var iconType = {};
            iconType['atm'] = "http://maps.google.com/mapfiles/ms/micons/dollar.png";
            iconType['bus_station'] = "http://maps.google.com/mapfiles/ms/micons/bus.png";
            //iconType['restaurant'] = "http://maps.google.com/mapfiles/ms/micons/restaurant.png";
            iconType['parking'] = "http://maps.google.com/mapfiles/ms/micons/parkinglot.png";
            var placeLoc = place.geometry.location;
            var marker = new google.maps.Marker({
              map : map,
              icon : iconType[place.types[0]],
              position : place.geometry.location
            });
    
            google.maps.event.addListener(marker, 'click', function() {
              infowindow.setContent(place.name);
              infowindow.open(map, this);
            });
    
            return marker;
          }
    
    
          google.maps.event.addDomListener(window, 'load', initialize);
        </script>
        <style type="text/css">
          code.prettyprint {
            display: block;
            border: 1px solid #ccc;
            margin-bottom: 1em;
          }
          #map {
            width: 100%;
            height: 500px;
            margin: 0;
          }
    
        </style>
      </head>
      <body>
        <input type="button" id="removeBtn" value="Remove all markers" />
        <div id="map"></div>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been an issue for others, but I've yet to find
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
im new at javascript and i can get this slider to work but not
I'm so close to figuring this out, i think. I'm new to javascript, but
I'm kinda new to javascript running on Apache but I have the following problem.
I've been working on this site for the past two weeks and everything has
I know this question has been asked many times here, but no answer has
This topic has been discussed several times on the web but all subjects none
I have been trying to sort this problem out for the last few days.
Update: This bug has been confirmed by at least two others. Even if you

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.