Google map not displaying marker array





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I am using this code to display a map depending on the post, which may or may not be displayed on the page. I am not initializing the map by default, since it isn't shown until user interacts.



function maps (postnum) {

var thisDiv = '#'+postnum+'-markers';

var delay = 10;
var infowindow = new google.maps.InfoWindow();

var map = new GMaps({
div: thisDiv,
lat: 0,
lng: 0,
zoom: 8,
disableDefaultUI: true,
zoomControl: true});

var bounds = new google.maps.LatLngBounds();

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

function geocodeAddress(address, next) {
geocoder.geocode({address:address}, function (results,status) {
if (status == google.maps.GeocoderStatus.OK) {
var p = results[0].geometry.location;
var lat = p.lat();
var lng = p.lng();
createMarker(address,lat,lng);
} else {
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
nextAddress--;
delay++;
} else {
}
}
next();
});
}

function createMarker(add,lat,lng) {

var contentString = add;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
setMap: map,
});

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

bounds.extend(marker.position);

}

var locations = [
'New Delhi, India',
'Mumbai, India',
'Bangaluru, Karnataka, India',
'Hyderabad, Ahemdabad, India',
'Gurgaon, Haryana, India'
];

var nextAddress = 0;

function theNext() {
if (nextAddress < locations.length) {
setTimeout(geocodeAddress(locations[nextAddress],theNext), delay);
nextAddress++;
} else {
map.fitBounds(bounds);
}
}

theNext();

};


I later call maps(postnum); once it should be displayed.



The map shows fine and the bounds work as well, but I am not seeing any markers. I have found similar questions, where the error was caused by not calling the map first.



Fiddle



How do I get around this if I don't want to call the map upon page load, rather later?










share|improve this question































    -1















    I am using this code to display a map depending on the post, which may or may not be displayed on the page. I am not initializing the map by default, since it isn't shown until user interacts.



    function maps (postnum) {

    var thisDiv = '#'+postnum+'-markers';

    var delay = 10;
    var infowindow = new google.maps.InfoWindow();

    var map = new GMaps({
    div: thisDiv,
    lat: 0,
    lng: 0,
    zoom: 8,
    disableDefaultUI: true,
    zoomControl: true});

    var bounds = new google.maps.LatLngBounds();

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

    function geocodeAddress(address, next) {
    geocoder.geocode({address:address}, function (results,status) {
    if (status == google.maps.GeocoderStatus.OK) {
    var p = results[0].geometry.location;
    var lat = p.lat();
    var lng = p.lng();
    createMarker(address,lat,lng);
    } else {
    if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
    nextAddress--;
    delay++;
    } else {
    }
    }
    next();
    });
    }

    function createMarker(add,lat,lng) {

    var contentString = add;
    var marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat,lng),
    setMap: map,
    });

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

    bounds.extend(marker.position);

    }

    var locations = [
    'New Delhi, India',
    'Mumbai, India',
    'Bangaluru, Karnataka, India',
    'Hyderabad, Ahemdabad, India',
    'Gurgaon, Haryana, India'
    ];

    var nextAddress = 0;

    function theNext() {
    if (nextAddress < locations.length) {
    setTimeout(geocodeAddress(locations[nextAddress],theNext), delay);
    nextAddress++;
    } else {
    map.fitBounds(bounds);
    }
    }

    theNext();

    };


    I later call maps(postnum); once it should be displayed.



    The map shows fine and the bounds work as well, but I am not seeing any markers. I have found similar questions, where the error was caused by not calling the map first.



    Fiddle



    How do I get around this if I don't want to call the map upon page load, rather later?










    share|improve this question



























      -1












      -1








      -1








      I am using this code to display a map depending on the post, which may or may not be displayed on the page. I am not initializing the map by default, since it isn't shown until user interacts.



      function maps (postnum) {

      var thisDiv = '#'+postnum+'-markers';

      var delay = 10;
      var infowindow = new google.maps.InfoWindow();

      var map = new GMaps({
      div: thisDiv,
      lat: 0,
      lng: 0,
      zoom: 8,
      disableDefaultUI: true,
      zoomControl: true});

      var bounds = new google.maps.LatLngBounds();

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

      function geocodeAddress(address, next) {
      geocoder.geocode({address:address}, function (results,status) {
      if (status == google.maps.GeocoderStatus.OK) {
      var p = results[0].geometry.location;
      var lat = p.lat();
      var lng = p.lng();
      createMarker(address,lat,lng);
      } else {
      if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
      nextAddress--;
      delay++;
      } else {
      }
      }
      next();
      });
      }

      function createMarker(add,lat,lng) {

      var contentString = add;
      var marker = new google.maps.Marker({
      position: new google.maps.LatLng(lat,lng),
      setMap: map,
      });

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

      bounds.extend(marker.position);

      }

      var locations = [
      'New Delhi, India',
      'Mumbai, India',
      'Bangaluru, Karnataka, India',
      'Hyderabad, Ahemdabad, India',
      'Gurgaon, Haryana, India'
      ];

      var nextAddress = 0;

      function theNext() {
      if (nextAddress < locations.length) {
      setTimeout(geocodeAddress(locations[nextAddress],theNext), delay);
      nextAddress++;
      } else {
      map.fitBounds(bounds);
      }
      }

      theNext();

      };


      I later call maps(postnum); once it should be displayed.



      The map shows fine and the bounds work as well, but I am not seeing any markers. I have found similar questions, where the error was caused by not calling the map first.



      Fiddle



      How do I get around this if I don't want to call the map upon page load, rather later?










      share|improve this question
















      I am using this code to display a map depending on the post, which may or may not be displayed on the page. I am not initializing the map by default, since it isn't shown until user interacts.



      function maps (postnum) {

      var thisDiv = '#'+postnum+'-markers';

      var delay = 10;
      var infowindow = new google.maps.InfoWindow();

      var map = new GMaps({
      div: thisDiv,
      lat: 0,
      lng: 0,
      zoom: 8,
      disableDefaultUI: true,
      zoomControl: true});

      var bounds = new google.maps.LatLngBounds();

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

      function geocodeAddress(address, next) {
      geocoder.geocode({address:address}, function (results,status) {
      if (status == google.maps.GeocoderStatus.OK) {
      var p = results[0].geometry.location;
      var lat = p.lat();
      var lng = p.lng();
      createMarker(address,lat,lng);
      } else {
      if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
      nextAddress--;
      delay++;
      } else {
      }
      }
      next();
      });
      }

      function createMarker(add,lat,lng) {

      var contentString = add;
      var marker = new google.maps.Marker({
      position: new google.maps.LatLng(lat,lng),
      setMap: map,
      });

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

      bounds.extend(marker.position);

      }

      var locations = [
      'New Delhi, India',
      'Mumbai, India',
      'Bangaluru, Karnataka, India',
      'Hyderabad, Ahemdabad, India',
      'Gurgaon, Haryana, India'
      ];

      var nextAddress = 0;

      function theNext() {
      if (nextAddress < locations.length) {
      setTimeout(geocodeAddress(locations[nextAddress],theNext), delay);
      nextAddress++;
      } else {
      map.fitBounds(bounds);
      }
      }

      theNext();

      };


      I later call maps(postnum); once it should be displayed.



      The map shows fine and the bounds work as well, but I am not seeing any markers. I have found similar questions, where the error was caused by not calling the map first.



      Fiddle



      How do I get around this if I don't want to call the map upon page load, rather later?







      javascript google-maps-api-3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 '18 at 13:32







      Fid

















      asked Nov 29 '18 at 6:37









      FidFid

      11110




      11110
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You have a typo in the marker construction. In the function createMarker:



          setMap: map,


          should be:



          map: map,


          updated fiddle



          screenshot of resulting map



          code snippet:






          var thisDiv = '1234-markers';

          var delay = 10;
          var infowindow = new google.maps.InfoWindow();

          var map = new google.maps.Map(document.getElementById(thisDiv), {
          center: new google.maps.LatLng(33.808678, -117.918921),
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
          });

          var bounds = new google.maps.LatLngBounds();

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

          function geocodeAddress(address, next) {
          geocoder.geocode({
          address: address
          }, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
          var p = results[0].geometry.location;
          var lat = p.lat();
          var lng = p.lng();
          createMarker(address, lat, lng);
          } else {
          if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
          nextAddress--;
          delay++;
          } else {}
          }
          next();
          });
          }

          function createMarker(add, lat, lng) {

          var contentString = add;
          var marker = new google.maps.Marker({
          position: new google.maps.LatLng(lat, lng),
          map: map,
          });

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

          bounds.extend(marker.position);

          }

          var locations = [
          'New Delhi, India',
          'Mumbai, India',
          'Bangaluru, Karnataka, India',
          'Hyderabad, Ahemdabad, India',
          'Gurgaon, Haryana, India'
          ];

          var nextAddress = 0;

          function theNext() {
          if (nextAddress < locations.length) {
          setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
          nextAddress++;
          } else {
          map.fitBounds(bounds);
          }
          }

          theNext();

          body {
          margin: 0;
          padding: 0;
          font: 12px sans-serif;
          }

          h1,
          p {
          margin: 0;
          padding: 0;
          }

          <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
          <div id="1234-markers" style="height: 400px;"></div>








          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533167%2fgoogle-map-not-displaying-marker-array%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You have a typo in the marker construction. In the function createMarker:



            setMap: map,


            should be:



            map: map,


            updated fiddle



            screenshot of resulting map



            code snippet:






            var thisDiv = '1234-markers';

            var delay = 10;
            var infowindow = new google.maps.InfoWindow();

            var map = new google.maps.Map(document.getElementById(thisDiv), {
            center: new google.maps.LatLng(33.808678, -117.918921),
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            });

            var bounds = new google.maps.LatLngBounds();

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

            function geocodeAddress(address, next) {
            geocoder.geocode({
            address: address
            }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
            var p = results[0].geometry.location;
            var lat = p.lat();
            var lng = p.lng();
            createMarker(address, lat, lng);
            } else {
            if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
            nextAddress--;
            delay++;
            } else {}
            }
            next();
            });
            }

            function createMarker(add, lat, lng) {

            var contentString = add;
            var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lng),
            map: map,
            });

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

            bounds.extend(marker.position);

            }

            var locations = [
            'New Delhi, India',
            'Mumbai, India',
            'Bangaluru, Karnataka, India',
            'Hyderabad, Ahemdabad, India',
            'Gurgaon, Haryana, India'
            ];

            var nextAddress = 0;

            function theNext() {
            if (nextAddress < locations.length) {
            setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
            nextAddress++;
            } else {
            map.fitBounds(bounds);
            }
            }

            theNext();

            body {
            margin: 0;
            padding: 0;
            font: 12px sans-serif;
            }

            h1,
            p {
            margin: 0;
            padding: 0;
            }

            <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
            <div id="1234-markers" style="height: 400px;"></div>








            share|improve this answer




























              1














              You have a typo in the marker construction. In the function createMarker:



              setMap: map,


              should be:



              map: map,


              updated fiddle



              screenshot of resulting map



              code snippet:






              var thisDiv = '1234-markers';

              var delay = 10;
              var infowindow = new google.maps.InfoWindow();

              var map = new google.maps.Map(document.getElementById(thisDiv), {
              center: new google.maps.LatLng(33.808678, -117.918921),
              zoom: 14,
              mapTypeId: google.maps.MapTypeId.ROADMAP
              });

              var bounds = new google.maps.LatLngBounds();

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

              function geocodeAddress(address, next) {
              geocoder.geocode({
              address: address
              }, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
              var p = results[0].geometry.location;
              var lat = p.lat();
              var lng = p.lng();
              createMarker(address, lat, lng);
              } else {
              if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
              nextAddress--;
              delay++;
              } else {}
              }
              next();
              });
              }

              function createMarker(add, lat, lng) {

              var contentString = add;
              var marker = new google.maps.Marker({
              position: new google.maps.LatLng(lat, lng),
              map: map,
              });

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

              bounds.extend(marker.position);

              }

              var locations = [
              'New Delhi, India',
              'Mumbai, India',
              'Bangaluru, Karnataka, India',
              'Hyderabad, Ahemdabad, India',
              'Gurgaon, Haryana, India'
              ];

              var nextAddress = 0;

              function theNext() {
              if (nextAddress < locations.length) {
              setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
              nextAddress++;
              } else {
              map.fitBounds(bounds);
              }
              }

              theNext();

              body {
              margin: 0;
              padding: 0;
              font: 12px sans-serif;
              }

              h1,
              p {
              margin: 0;
              padding: 0;
              }

              <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
              <div id="1234-markers" style="height: 400px;"></div>








              share|improve this answer


























                1












                1








                1







                You have a typo in the marker construction. In the function createMarker:



                setMap: map,


                should be:



                map: map,


                updated fiddle



                screenshot of resulting map



                code snippet:






                var thisDiv = '1234-markers';

                var delay = 10;
                var infowindow = new google.maps.InfoWindow();

                var map = new google.maps.Map(document.getElementById(thisDiv), {
                center: new google.maps.LatLng(33.808678, -117.918921),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
                });

                var bounds = new google.maps.LatLngBounds();

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

                function geocodeAddress(address, next) {
                geocoder.geocode({
                address: address
                }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                var p = results[0].geometry.location;
                var lat = p.lat();
                var lng = p.lng();
                createMarker(address, lat, lng);
                } else {
                if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                nextAddress--;
                delay++;
                } else {}
                }
                next();
                });
                }

                function createMarker(add, lat, lng) {

                var contentString = add;
                var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat, lng),
                map: map,
                });

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

                bounds.extend(marker.position);

                }

                var locations = [
                'New Delhi, India',
                'Mumbai, India',
                'Bangaluru, Karnataka, India',
                'Hyderabad, Ahemdabad, India',
                'Gurgaon, Haryana, India'
                ];

                var nextAddress = 0;

                function theNext() {
                if (nextAddress < locations.length) {
                setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
                nextAddress++;
                } else {
                map.fitBounds(bounds);
                }
                }

                theNext();

                body {
                margin: 0;
                padding: 0;
                font: 12px sans-serif;
                }

                h1,
                p {
                margin: 0;
                padding: 0;
                }

                <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
                <div id="1234-markers" style="height: 400px;"></div>








                share|improve this answer













                You have a typo in the marker construction. In the function createMarker:



                setMap: map,


                should be:



                map: map,


                updated fiddle



                screenshot of resulting map



                code snippet:






                var thisDiv = '1234-markers';

                var delay = 10;
                var infowindow = new google.maps.InfoWindow();

                var map = new google.maps.Map(document.getElementById(thisDiv), {
                center: new google.maps.LatLng(33.808678, -117.918921),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
                });

                var bounds = new google.maps.LatLngBounds();

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

                function geocodeAddress(address, next) {
                geocoder.geocode({
                address: address
                }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                var p = results[0].geometry.location;
                var lat = p.lat();
                var lng = p.lng();
                createMarker(address, lat, lng);
                } else {
                if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                nextAddress--;
                delay++;
                } else {}
                }
                next();
                });
                }

                function createMarker(add, lat, lng) {

                var contentString = add;
                var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat, lng),
                map: map,
                });

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

                bounds.extend(marker.position);

                }

                var locations = [
                'New Delhi, India',
                'Mumbai, India',
                'Bangaluru, Karnataka, India',
                'Hyderabad, Ahemdabad, India',
                'Gurgaon, Haryana, India'
                ];

                var nextAddress = 0;

                function theNext() {
                if (nextAddress < locations.length) {
                setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
                nextAddress++;
                } else {
                map.fitBounds(bounds);
                }
                }

                theNext();

                body {
                margin: 0;
                padding: 0;
                font: 12px sans-serif;
                }

                h1,
                p {
                margin: 0;
                padding: 0;
                }

                <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
                <div id="1234-markers" style="height: 400px;"></div>








                var thisDiv = '1234-markers';

                var delay = 10;
                var infowindow = new google.maps.InfoWindow();

                var map = new google.maps.Map(document.getElementById(thisDiv), {
                center: new google.maps.LatLng(33.808678, -117.918921),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
                });

                var bounds = new google.maps.LatLngBounds();

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

                function geocodeAddress(address, next) {
                geocoder.geocode({
                address: address
                }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                var p = results[0].geometry.location;
                var lat = p.lat();
                var lng = p.lng();
                createMarker(address, lat, lng);
                } else {
                if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                nextAddress--;
                delay++;
                } else {}
                }
                next();
                });
                }

                function createMarker(add, lat, lng) {

                var contentString = add;
                var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat, lng),
                map: map,
                });

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

                bounds.extend(marker.position);

                }

                var locations = [
                'New Delhi, India',
                'Mumbai, India',
                'Bangaluru, Karnataka, India',
                'Hyderabad, Ahemdabad, India',
                'Gurgaon, Haryana, India'
                ];

                var nextAddress = 0;

                function theNext() {
                if (nextAddress < locations.length) {
                setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
                nextAddress++;
                } else {
                map.fitBounds(bounds);
                }
                }

                theNext();

                body {
                margin: 0;
                padding: 0;
                font: 12px sans-serif;
                }

                h1,
                p {
                margin: 0;
                padding: 0;
                }

                <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
                <div id="1234-markers" style="height: 400px;"></div>





                var thisDiv = '1234-markers';

                var delay = 10;
                var infowindow = new google.maps.InfoWindow();

                var map = new google.maps.Map(document.getElementById(thisDiv), {
                center: new google.maps.LatLng(33.808678, -117.918921),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
                });

                var bounds = new google.maps.LatLngBounds();

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

                function geocodeAddress(address, next) {
                geocoder.geocode({
                address: address
                }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                var p = results[0].geometry.location;
                var lat = p.lat();
                var lng = p.lng();
                createMarker(address, lat, lng);
                } else {
                if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                nextAddress--;
                delay++;
                } else {}
                }
                next();
                });
                }

                function createMarker(add, lat, lng) {

                var contentString = add;
                var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat, lng),
                map: map,
                });

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

                bounds.extend(marker.position);

                }

                var locations = [
                'New Delhi, India',
                'Mumbai, India',
                'Bangaluru, Karnataka, India',
                'Hyderabad, Ahemdabad, India',
                'Gurgaon, Haryana, India'
                ];

                var nextAddress = 0;

                function theNext() {
                if (nextAddress < locations.length) {
                setTimeout(geocodeAddress(locations[nextAddress], theNext), delay);
                nextAddress++;
                } else {
                map.fitBounds(bounds);
                }
                }

                theNext();

                body {
                margin: 0;
                padding: 0;
                font: 12px sans-serif;
                }

                h1,
                p {
                margin: 0;
                padding: 0;
                }

                <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3"></script>
                <div id="1234-markers" style="height: 400px;"></div>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 29 '18 at 14:09









                geocodezipgeocodezip

                128k10149179




                128k10149179
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533167%2fgoogle-map-not-displaying-marker-array%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)