Rendering polygon with Google Static Maps API URL

2019-03-30 07:40发布

问题:

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..

回答1:

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