15

Does anyone know how to give a different color to each country in a google map?

e.g:

in the world map

Blue overlay to UK, then RED china...etc

I wonder if google provide API to give color to each country

Thanks

j0k
  • 22,600
  • 28
  • 79
  • 90
adhitia hidayat
  • 185
  • 1
  • 1
  • 6
  • Maybe this [link](https://stackoverflow.com/questions/44308091/assign-different-color-to-each-country-in-the-google-map-api?rq=1) will be useful. – krzysztof May 06 '19 at 20:56

4 Answers4

13

Using Google Maps this is really not easy, as @oezi said you would need to build overlays of every country you want to color, which frankly sounds like a mess.

But if you don't need all of the functionalities of Google Maps, perhaps you can use a Map Chart from the fantastic Google Chart Tools (aka Chart API). You can check and tinker with a working example of a Colored Map (among some others) in the interactive Chart Wizard

2017 UPDATE: This answer is quite old and as such the Map Charts API has been deprecated by Google. You can use the Geocharts from the Google Charts API instead:

https://developers.google.com/chart/interactive/docs/gallery/geochart

Hope this helps!

danii
  • 5,553
  • 2
  • 21
  • 23
  • Here's a great site to help you generate your UI: [mapstyle.withgoogle.com](https://mapstyle.withgoogle.com/) – ajwaka Aug 06 '18 at 14:44
5

you may check this question,it's the same question you are asking. How to color countries using google maps?

it's talking about google Geocharts in google maps.

Community
  • 1
  • 1
Prog Mania
  • 615
  • 9
  • 14
2

there is a possibility to change the map style. and there is a very nice interactive example here - but, as far as i can see, it isn't possible to change the style of a specific country using this, so you'll have to build your own overlays using polygons.

oezi
  • 51,017
  • 10
  • 98
  • 115
2

First, find the shape file in .kml format. Tip: try googling "kml uk" or "kml china".

Once you have the KMLfile, host it somewhere and then call it as a var inside your Google Maps API initMap like this:

var myCustomRegion = new google.maps.KmlLayer({
    url: 'FULL_URL_TO_YOUR_SHAPE_FILE',
    map: map
});

Now your shape is laid into your map.

You can style the shape using the <LineStyle> and <PolyStyle> tags inside the KML file itself.

MarkPraschan
  • 560
  • 6
  • 8