- Posted On 20 February 2015
- By
- In Programming
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.
- Tags :
- jQueryJavascript
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.
Visual Studio 2008 Shell and TFS integration
Visual Studio 2008 Shell and TFS integration is the problem for all newbies of BIDS and TFS. Here is the solution.
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.
Assembla - Free and private repository to manage your source code online with SVN subversion hosting
With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.
Best CSS Gradient background generator tools online
Here are some best CSS gradient background code generator online tools using which you can create a cross browser css code for gradient backgrounds.