Put marker on country

2019-08-18 19:48发布

I have a bunch of country names. Like hundreds. I want to add a marker on each of the countries that I have. If I use geocoding it says I reach the limit of requests allowed to geocode my names. So isn't there an entire "client way" of doing this without contacting the server for coordinates of the country?

1条回答
迷人小祖宗
2楼-- · 2019-08-18 20:26

You can create a kml file with the countries you want and their coordinates and then consume this in your map code.

KML howto

var map = new google.maps.Map(document.getElementById("map_canvas"), 0ptions);
var kmzLayer = new google.maps.KmlLayer('http://yoursite/countries.kmz');
kmzLayer.setMap(map);

You can add the markers to the kml file as in this example

Another option would be to store your countries and geocodes in json and then iterate over the json to add the markers.

Stackoverflow question Take a look at this example which allows you to click on a country and the country name and flag are shown.

查看更多
登录 后发表回答