我正在使用Google Maps v3,并且我需要为地图添加不同区域的边框线。例如,在Google Maps中自动显示所有美国州界线。我需要为不同的国家做同样的事情。例如,显示英格兰所有城市的边界。
请问如何在Google Maps API v3中实现这一功能?
谢谢, Yossi
我正在使用Google Maps v3,并且我需要为地图添加不同区域的边框线。例如,在Google Maps中自动显示所有美国州界线。我需要为不同的国家做同样的事情。例如,显示英格兰所有城市的边界。
请问如何在Google Maps API v3中实现这一功能?
谢谢, Yossi
我发现在互联网上很难找到边界数据——即使对于像加拿大省份这样的著名边界也是如此。尝试使用Google Maps Engine。在地图上绘制封闭多边形来标记你的边界。接下来点击文件夹并执行“导出为KML”操作。该格式为经度、纬度、高度(含多个点)。这可以轻松转换为其他格式。
例如,我使用了一个简单的Perl脚本将其从KML转换为我所需的格式。
while (<>) {
chop;
if (/<name>/) {
s/<name>//g;
s/<\/name>//g;
s/^\s+//; # strip whitespace
s/\s+$//; # strip whitespace
print "<state colour=\"red\" name=\"$_\">\n";
}
if (/<coordinates/) {
s/<coordinates>//;
s/<\/coordinates>//;
s/,0.0\s*/,/g;
@array = split(",");
for ($i = 0; $i < @array; $i = $i + 2) {
if ($array[$i+1] && $array[$i]) {
$array[$i+1] =~ s/^\s+//; # strip whitespace
$array[$i+1] =~ s/\s+$//; # strip whitespace
$array[$i] =~ s/^\s+//; # strip whitespace
$array[$i] =~ s/\s+$//; # strip whitespace
print "<point lat=\"" . $array[$i+1] . "\" lng=\"" . $array[$i] . "\" \/>\n";
}
}
print "</state>\n";
}