Put marker on country

佐手、 提交于 2020-01-06 20:08:01

问题


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:


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.



来源:https://stackoverflow.com/questions/11154353/put-marker-on-country

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!