Rendering polygon with Google Static Maps API URL
Asked Answered
D

1

6

I created a script to store dynamic map inputs by appending attributes to a Static Maps URL (so we can refer back to it after a user submits).

For reasons I can't yet determine, the Polygon is not rendering at all with the basic static maps URL, but it works with a 3rd party site's static maps function. According to Static Maps API examples there should be no issue, but I can't seem to recreate the Polygon.

Working version (with same attributes in URL, though it ignores Satellite and zoom resolution) from 3rd Party site.

Desired version missing the polygon.

The question is: Am I missing some parameter? I do have an API key which I removed from the URL, so that must not be the issue..

Dowager answered 30/10, 2012 at 20:58 Comment(5)
Why are those two links COMPLETELY Different?Sonstrom
Note that the attributes are the same.. the 3rd party site has a unique URL before the ../staticmap? part. I just made sure they had the same attributes-- check the links again.Dowager
Just an FYI off-topic, if you want to manually make links in your text, which I find easier than how the editor does it, links look like [Link Text] (Url) without a space between the ](.Sonstrom
Your working version is now giving a Bad Request.Sonstrom
Sorry-- working now. Appears that the URL gets encoded on the 3rd party site. Main attributes I'm matching are the following: center=33.402285,-111.94271500000002&zoom=20&size=600x600&maptype=satellite&sensor=false&path=color:red|weight:1|fill:white|opacity:0.75|33.4022475,-111.9426775|33.4022475,-111.9427525|33.4023225,-111.9427525|33.4023225,-111.9426775|33.4022475,-111.9426775Dowager
S
23

Your original Desired Version uses a parameter that Google does not support. Removing just opacity:0| and it works:

http://maps.googleapis.com/maps/api/staticmap?center=33.402285,-111.94271500000002&zoom=20&size=600x600&maptype=satellite&sensor=false&path=color%3ared|weight:1|fill%3awhite|33.4022475,-111.9426775|33.4022475,-111.9427525|33.4023225,-111.9427525|33.4023225,-111.9426775|33.4022475,-111.9426775

Opacity on google maps is set in the color as a 32-bit hexadecimal value, so

  • Thin blue line, 0% opacity: path=color:0x0000ff00
  • Solid red line with 100% opacity: path=color:0xff0000ff
  • The default is 50% if you pass a 24-bit color: 0x0000ff (50% opacity, blue)

So I think this is what you are looking for (or really close):

http://maps.googleapis.com/maps/api/staticmap?center=33.402285,-111.942715&zoom=20&size=600x600&maptype=satellite&sensor=false&path=color:red|weight:1|fillcolor:white|33.4022475,-111.9426775|33.4022475,-111.9427525|33.4023225,-111.9427525|33.4023225,-111.9426775|33.4022475,-111.9426775

Sonstrom answered 30/10, 2012 at 22:46 Comment(4)
Hallelujah! My savior! Thanks Erik-- that fixed the problem. If anyone is curious of how I built the static maps URL, feel free to contact me! We use a fairly dynamic polygon tool at my office..Dowager
If your tool is home built, I would highly recommend allowing it to also export encoded paths.Sonstrom
Thanks Erik-- I'll take a look at that documentation. If I'm not mistaken, it appears that the main benefit is that it secures the coordinate data and shortens the URL. Is that assessment accurate or are there additional benefits?Dowager
I don't know about secures the coordinates but it significantly shortens the path points.Sonstrom

© 2022 - 2024 — McMap. All rights reserved.