Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight whole countries in Google Maps

Tags:

google-maps

I have a general question about Google Maps. I want to use Google Maps just for germany, but of course the neighbor countries are shown as well. The border of germany is rarely visible.

Is there a possibility to fade out the other, not used countries?

like image 645
Armin Avatar asked Dec 29 '11 17:12

Armin


People also ask

How do I highlight countries on Google Maps?

To achieve this, you will basically need to look for the coordinates of the state or country on GADM. Once you have them, draw a shape on the Google Maps with the Polygon object providing an array with all the coordinates that play basically as borders of the place that you want to highlight.

Why are some countries not highlighted in Google Maps?

That's because Google shifts the borders between countries, depending on what country you are in when you look at them. That is, Google customizes its maps, depending on what the viewer expects to see.

Can you highlight areas on Google Maps?

You can trace a path or highlight an area on your map by drawing lines and shapes.

Can you color code Google Maps?

Changing Map Styles Click on the option labeled Tools and then click on Change map. Once there, click on the button labeled Change feature styles. There are plenty of options for changing the different styles of your markers, which includes changing their color.


2 Answers

I was able to do this using the public World Country Boundaries.kml Fusion Table.

You'll need to add it as a Fusion Table Layer to your map.


Firstly initialize a map zoomed out right out, centered so we can see most countries:

var map = new google.maps.Map(document.getElementById('map-canvas'), {   center: new google.maps.LatLng(30,0),   zoom: 2,   mapTypeId: google.maps.MapTypeId.ROADMAP }); 

Next add the FusionTablesLayer:

var world_geometry = new google.maps.FusionTablesLayer({   query: {     select: 'geometry',     from: '1N2LBk4JHwWpOY4d9fobIn27lfnZ5MDy-NoqqRpk'   },   map: map,   suppressInfoWindows: true }); 

That looks like this:

all countries


With regard to:

Is there a possibility to fade out the other, not used countries?

If you look at the Fusion Table you'll see there are columns for Name and ISO_2DIGIT. We can filter on these by passing a where condition to the FusionTablesLayer, e.g:

  query: {     select: 'geometry',     from: '1N2LBk4JHwWpOY4d9fobIn27lfnZ5MDy-NoqqRpk',     where: "ISO_2DIGIT IN ('US', 'GB', 'DE')"   }, 

To give:

filter countries with where

like image 134
davetapley Avatar answered Sep 19 '22 19:09

davetapley


For any one who ends up here in the future, this seems to now be handled very well by Google Charts, the latest implementation of the deprecated link above

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

like image 42
mgibson Avatar answered Sep 22 '22 19:09

mgibson