How can I display country borders, US state borders, and city borders using Google Maps?

后端 未结 3 1471
一个人的身影
一个人的身影 2020-12-18 09:19

I am using Google Maps v3 and I need to add border lines for different areas to my map. For example, in Google Maps all the US State borders are shown automatically. I need

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 09:30

    I found it difficult to find border/boundary data on Internet - even for well-known boundaries like Canadian provinces. Try using Google Maps Engine. Draw your borders on the map as closed polygons. Next click folder and do "export to KML". The format is long, lat, altitude (with multiple points). This can easily be converted to other formats.

    For example, I used a simple perl script to convert from KML to the format I wanted.

    while (<>) {
    chop;
    if (//) {
        s///g;
        s/<\/name>//g;
        s/^\s+//; # strip whitespace
        s/\s+$//; # strip whitespace
        print "\n";
    }
    if (///;
        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  "\n";
    
            }
        }
            print "\n";
    }
    

提交回复
热议问题