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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:20:31+00:00 2026-05-31T21:20:31+00:00

This is a code sample taken from the Google Maps API developer’s guide. I’m

  • 0

This is a code sample taken from the Google Maps API developer’s guide. I’m not super experienced with JavaScript, but I have never seen this syntax before. The portion which confuses me is the first part, where they say “var citymap={};” and then seemingly go on to declare a bunch of citymap keys. Then, later, they say ” for (var city in citymap) {” etc.

Is this the only/the proper method for making a map in JavaScript?

// Create an object containing LatLng, population.
var citymap = {};
citymap['chicago'] = {
  center: new google.maps.LatLng(41.878113, -87.629798),
  population: 2842518
};
citymap['newyork'] = {
  center: new google.maps.LatLng(40.714352, -74.005973),
  population: 8143197
};
citymap['losangeles'] = {
  center: new google.maps.LatLng(34.052234, -118.243684),
  population: 3844829
}
var cityCircle;

function initialize() {
  var mapOptions = {
    zoom: 4,
    center: new google.maps.LatLng(37.09024, -95.712891),
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };

  var map = new google.maps.Map(document.getElementById("map_canvas"),
      mapOptions);

  for (var city in citymap) {
    // Construct the circle for each value in citymap. We scale population by 20.
    var populationOptions = {
      strokeColor: "#FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: "#FF0000",
      fillOpacity: 0.35,
      map: map,
      center: citymap[city].center,
      radius: citymap[city].population / 20
    };
    cityCircle = new google.maps.Circle(populationOptions);
  }
}
  • 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-31T21:20:33+00:00Added an answer on May 31, 2026 at 9:20 pm

    Let me try to explain each bit of code …

    var citymap = {};
    

    This creates an empty object … the following adds values to the object :

    citymap['chicago'] = {
      center: new google.maps.LatLng(41.878113, -87.629798),
      population: 2842518
    };
    

    This adds a new key (‘chicago’) and adds some properties to it (center and population) the final but which loops the object is

    for (var city in citymap) {
    

    this statement loops the citymap object, assigning city to the key of each object. To access the properties the code uses

    citymap[city].center
    citymap[city].population
    

    Its the best way to create and loop and object with multiple values. There is some really good documentation here on working with Objects in JavaScript

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

Sidebar

Related Questions

Why does this code (taken from the demo sample at jquery ui), doesn't work
I have this sample code for async operations (copied from the interwebs) public class
code sample taken from MSDN public class Test { public static void Main() {
I try to access information from Twitter and I followed this link: http://code.google.com/p/sociallib/wiki/SocialLibGuide I
I have the following code taken straight from the NavBar sample code from Apple.
I'm reading this code sample : And since I don't know C#, I decided
In this particular code sample I want to reference the second overloaded method (int
I'm trying to learn the Enterprise Library. I found this useful code sample to
In this sample code the URL of the app seems to be determined by
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:

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.