我想使用 Javascript 获取一个国家的中心坐标。是否有任何 xml 文件提供这种数据,用于 Web 应用程序?我基本上是在尝试使用 OpenLayers 中的国家/地区名称将数据放在 map 上。
最佳答案
使用 Google Maps API你可以使用Geocoder为此上课。
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{ address : "Germany" },
function(results) {
window.alert(results[0].geometry.bounds.getCenter());
});
您可能想要检查 results[]
数组,而不仅仅是获取索引 0,但这应该让您朝着正确的方向开始。
关于javascript - Javascript 中国家/地区的中心坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8930491/