37

I'm building a web application that is going to dynamically highlight certain U.S. states and Canadian provinces on a Google Map, based on buttons and click events.

Plan A) Polygons

My primary idea for this was to draw Polygons. For this I need lists of coordinates (latitude + longitude) of all state and province outlines (clockwise or counter-clockwise). On government websites I found all sorts of different formats (i.e. E00), but I have trouble converting these formats into a simple list of coordinates, that I could use to create markers or a polygon on a map. Do you have any tips where to get these coordinates?

Plan B) Overlays

AFAIK, if you use overlays on Google Maps, they become pixelated as you zoom in further (or can you overlay SVGs?) In my case I would need 50 + 11 overlays in the worst-case (all states and all provinces). Is that still possible with Google Maps or will it get unsuably slow?

I'm a bit startled that there isn't a straight-forward way to highlight a state or province, as I would think this is a very common tasks for people using an API for maps.

Thanks in advance

motto
  • 1,305
  • 3
  • 16
  • 30
  • 1
    Take a look at [this question](http://stackoverflow.com/questions/10874686/google-maps-v3-draw-german-state-polygons/14336434#14336434). – Maarten Jan 15 '13 at 11:10

4 Answers4

80

I've got XML for US state polygons here. I use them like this.

I deliberately kept the detail fairly light to reduce the loading time and end up with a map that's reasonably responsive in slow browsers.

I don't have anything for Canada.

Mike Williams
  • 7,739
  • 2
  • 24
  • 12
  • Thanks a bunch! Your data worked without any problems. Like the level of detail too. You rock! – motto Nov 29 '09 at 21:38
  • 2
    @Mike Williams: Why do the boundaries of adjacent states fit so badly together? I understand that there is some limit in resolution, but there is no reason for gaps and overlaps (visible in higher zoom levels) between adjacent states. – Curd Jan 02 '10 at 20:02
  • 1
    Do you know where I can find this data at the city level? – MadHacker Feb 24 '12 at 03:18
  • Any idea where I can get a file with a bit more detail? – Burferd Apr 16 '12 at 20:08
  • 7
    Try the [Natural Earth dataset](http://www.naturalearthdata.com/). It is also available in [FusionTables](http://blog.thematicmapping.org/2011/02/natural-earth-vectors-in-cloud.html). – geocodezip Jun 16 '12 at 18:48
  • Thanks for the post Mike. I'm also trying to keep things 'light'. – jjwdesign Dec 19 '12 at 05:16
  • @geocodezip's comment should be an answer of its own, that Natural Earth website is awesome! – Ben Feb 06 '13 at 23:07
  • @Mike Williams, where did you get that XML file for the US state polygons? I am looking for one exactly like that one, but I would like it to include state counties. Any help you can provide is appreciated. – tentmaking Apr 18 '13 at 05:36
  • This set is awesome but is missing District of Columbia - it's lumped into Maryland :( – SaltyNuts Oct 17 '13 at 15:00
  • I need coordinates for all city boundaries in Pakistan. Can anyone help please... – Waqas Ali Khan Dec 04 '14 at 15:49
  • @Mike Willians, seconding Curd's concerns. New York and New Jersey have overlapping regions: http://i.imgur.com/tjdSwPS.jpg – Bing Mar 16 '17 at 22:48
5

Using the XML provided, I created a JSON file with a dictionary that includes the 50 states, Washington D.C. and a rough outline of the Canadian provinces to address SaltyNuts' comment as well as Mike Williams note of not having anything for Canada json.

This handy online tool from BirdTheme was what I used to draw the polygons for the provinces for anyone else who needs different levels of detail or to create their own set of coordinates.

rene
  • 41,474
  • 78
  • 114
  • 152
northcott-j
  • 79
  • 1
  • 3
2

Old question but you can get a more detailed set of points for each US state border from the google website at https://developers.google.com/kml/documentation/us_states.kml

It needs a little bit of parsing of the xml though.

artemisian
  • 2,976
  • 1
  • 22
  • 23
0

Here's the info for Canadian Provinces. I've copied only the first GPS coordinate from the Google Map link.

/**
 * Searched for Alberta, Canada and copied the first thing after the @ sign
 * @see https://www.google.bg/maps/place/Yukon+Territory,+Canada/@64.5610006,-141.332713,5z/data=!3m1!4b1!4m5!3m4!1s0x51178198b4528b89:0x2e149cd561cc96ea!8m2!3d64.2823274!4d-135?hl=en
 * @var array
 */
$provinces_gps = array(
    "AB" => "54.1784838,-123.9541477",
    "BC" => "53.8348151,-135.5103986",
    "MB" => "54.1798816,-104.4465713",
    "NB" => "46.2679312,-68.6551949",
    "NL" => "53.1668149,-69.1783083",
    "NT" => "68.4817407,-136.7732486",
    "NS" => "45.2906308,-65.2759181",
    "NU" => "63.5954344,-124.1555502",
    "ON" => "48.9347914,-93.7155729",
    "PE" => "46.5031512,-63.7525627",
    "QC" => "53.4650568,-77.3895206",
    "SK" => "54.1797758,-114.6389862",
    "YT" => "64.5610006,-141.332713",
);
Svetoslav Marinov
  • 1,498
  • 14
  • 11