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

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.

What is Hoisting in JavaScript?

Hoisting in JavaScript, one of the most misunderstood or little understood concept in the JavaScript and remain famous as interview question for JavaScript developers and now also for angular js developer. Lets check out what it means exactly.

Visual Studio Code - Lighweight but powerful source code editor available for Windows, OS X and Linux

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, OS X and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (C++, C#, Python, PHP) and runtimes.

How to post JSON string as a string in jQuery AJAX

Know how to post JSON String as string to the action method of controller in MVC.

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.

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!