Subscribe - It's FREE!!

Stay Connected Here

Stay Updated With Us Here


Highlight multiple cities in google maps (Geo Chart)

Share with WhatsApp

This post covers information about how you can highlight regions (state,city) on Google Map using their Geo Chart API.

In this example, I will highlight the cities (metros) of USA. Lets start step by step.

First create one div in your HTML like below in which we will load the Google Map.

<div id="map_container"></div>

Then you need to reference the Google Map API library from here (we have loaded Geo chart specific module).

Now we will write some JavaScript to load the map and highlight the cities.

First I have created the object of Geo Chart by following code.

var geochart = new google.visualization.GeoChart(document.getElementById('map_container'));

Then I have defined data table which has the two column data, in first column I have specified the DMA Region code of the city and in second I have specified the index of the color (as defined in options).

(In Google Map, to highlight city we need to use their respective DMA Region Code, you can find/download the all list here )

In this example, I have used following cities and their respective DMA region codes.

  • 619 - Springfield, MO
  • 803 - Los Angeles, CA
  • 545 - Greenville-New Bern-Washington, NC
  • 630 - Birmingham, AL
  • 800 - Bakersfield, CA
  • 698 - Montgomery (Selma), AL
  • 522 - Columbus, GA

Now I have created a set of options in which I have also specified the colors to highlight above cities.

  var options = {
            displayMode: 'regions',
            region: "US",
            legend: "none",
            width: 600,
            height: 500,
            resolution: 'metros',
            colors: ['red', 'blue', 'orange']

(To know in detail about different configuration options you can visit this link, here you will find that "resolution=metros" is only available for US map so for the details like such you must refer this link.)

Now we have defined all the data and options so we can load the map by following code.

 geochart.draw(data, options);

That's it. Now if you run this HTML page you will find the USA map with above cities highlited in different colours.

Below is he live fiddle of the above code.

Hope you have liked this simple post. Do share your thoughts in comment section below. Thanks.

If you enjoyed this post take 5 seconds to share it! Be Socialable. :-)

Share with WhatsApp

Posts To Read Next

Typewriter - Automatic TypeScript Template generation from C# classes in Visual Studio

Typewriter, an extension for visual studio that generates TypeScript files from C# code files using TypeScript templates. Convert your C# model classes to TypeScript automatically.

How to call click or any event only once in jQuery

Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.

Top 10 Visual Studio things which can boost developers coding speed

Visual Studio 2012 provides some coding features by which you can code faster if use them properly. This post will cover top 10 things among them to boost your development speed.

Copy changed data in table from one database to another in SQL stored procedure

How to copy or merge changed data in table from one database to another having same schema is the topic of this post.

Swagger - Powerful Opensource Framework for RESTful API

With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. Swagger Editor allows you to generate code, documentation with ease.

Your opinion is valuable for us! Comments, suggetions are welcome.

Submit your Email Id to stay updated with us and get notified with our new posts. It's FREE!
Vu 32'' TV Vu 24'' TV
We know this popup is disturbing you!
But We would greatly appreciate if you share us with your friends below!

It will not take more than 2 seconds but will motivate us greatly to write more,share more!