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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:12:26+00:00 2026-05-16T20:12:26+00:00

I am playing around with the Google Maps API V3. I want to create

  • 0

I am playing around with the Google Maps API V3.

I want to create a series of markers on a map.

I followed a tutorial and got:

Now this code adds one marker – the first one.

I am completely new to Javascript but from my PHP knowledge, I am thinking that the reason this is not working is because all of the markers are being stored in the var named ‘m’.

I.E Number 2 replaces Number 1

My confusion however is that if this were the case, Marker 2 would be shown not Marker 1.

Could anyone postulate a possible explanation/fix?

Thanks

Editted code below:

function initialize(){
// Creating a map
var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: new google.maps.LatLng(53.0123601276819, -2.44519164333635),
  mapTypeId: google.maps.MapTypeId.ROADMAP
});


var m = [];

function addMarker(title, lat, lng) {
m = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map,
title: title,  
clickable: true 
});


}



addMarker('Home', 53.0682143712504, -2.52150736731894);
addMarker('Away', 53.0123601276819, -2.44519164333635);



}
  • 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-05-16T20:12:27+00:00Added an answer on May 16, 2026 at 8:12 pm

    I suspect the problem is that you’re trying to treat the object “m” as if it were an array. Declare it like this:

    var m = [];
    

    and see what happens. There’s no “push” function on plain objects, so that line is throwing an exception after your first marker is added.

    The Javascript error console, however manifested by the browser you’re using, should always be open while you’re trying out new code. Well, maybe not always, but certainly the minute something weird happens.

    edit — The call to the .push() function in your code is fine; the problem was that you were trying to call it from something that wasn’t an array. All the function does is extend the array with the given element. Javascript arrays are somewhat weird, and the main magic has to do with how the runtime maintains the value of the “length” attribute. You can more directly extend an array like this:

    arr[arr.length] = newValue;
    

    You can also simply use some numeric index computed in some way:

    arr[pick_a_number()] = newValue;
    

    When you do that, the runtime makes sure that the “length” attribute is correctly updated, should the number used as an index be greater than the current value.

    Now, back to your updated code. Now it works because you’re adding points to the map in succession and not triggering any exceptions. However, by writing:

    m = google.whatever( ... );
    

    you are no longer adding those points to an array – you’re reassigning the variable “m” to one of the points, over and over again. Change it back to “push” and — if you also change the declaration of “m” as I suggested — it will still work, and you’ll get your array populated correctly.

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

Sidebar

Related Questions

I am playing around with the Google API Map Activity. Recently Google Maps for
Hi all I was playing around with the Google Maps Directions API and in
I've been playing around with the google maps api through javascript (I'm also new
Playing around with Google Maps these days, with some directions. I have a map
I'm playing around with the Google Checkout API and I want to pull it
I've been playing around with the Fusion Tables/Google Maps stuff to create some flight
I am currently playing around with Google's Voice Recognition API for Android SDK. What
I'm playing around with Google maps for the first time, so I looked at
I'm playing around with Google Buzz API from Python, During the OAuth process when
I am new to Android location/google maps. And I have been playing around with

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.