문제

I'm trying to get images with the Google Maps Image API of polygons representing areas of the UK. For some reason the imaging doesn't work when the polygon has too many coordinates and I can't find out why.

I'm encoding the polygons into the url as described here using the rails polylines gem.

A polygon of Camden in London is made with the following coordinates:

coords = [[-0.120544, 51.531198], [-0.127403, 51.533038], [-0.12757, 51.544915], [-0.139614, 51.558465], [-0.140785, 51.56867], [-0.172904, 51.574357], [-0.200339, 51.553112], [-0.215729, 51.553112], [-0.210376, 51.545751], [-0.190134, 51.532201], [-0.179428, 51.537889], [-0.172067, 51.536049], [-0.155841, 51.535213], [-0.150655, 51.526012], [-0.135097, 51.517648], [-0.131585, 51.512295], [-0.12389, 51.516979], [-0.114856, 51.516979], [-0.108834, 51.521161]] 

Which when used with the gem produces an encoded string:

enc = Polylines::Encoder.encode_points(coords)
-> jpV_uoyHzi@oJ`@giAfjAusAjFw~@tgEqb@njDxcCd_B?m`@~l@q}BtsA{aAqb@_m@nJmdBfDk_@nx@g`Bfs@}Tl`@co@g\\mw@?ud@cY

Then when placed in the API url doesn't produce a polygon (click here).

But if I cut the coordinates in half, limiting the coordinates, it does produce a polygon.

enc = Polylines::Encoder.encode_points([[51.531198, -0.120544], [51.533038, -0.127403], [51.544915, -0.12757], [51.558465, -0.139614], [51.56867, -0.140785], [51.574357, -0.172904], [51.553112, -0.200339], [51.553112, -0.215729]])
-> _uoyHjpVoJzi@giA`@usAfjAw~@jFqb@tgExcCnjD?d_B

Any ideas why? I can't find any documented limits in this API with regards to encoded polygons.

도움이 되었습니까?

해결책

You forgot to urlencode the encode path:

Important: The discussion of URL parameters below use examples that for clarity are given in their pre-escaping form. Before sending any request to the API, its parameters should be properly URL encoded. For example, many parameters use a pipe character (|) as a separator, which should be encoded as %7C in the final URL, as in the quick example at the top of this document.

urlencoded path in URL: http://maps.googleapis.com/maps/api/staticmap?scale=2&size=1000x1000&sensor=false&path=color:0044ff|weight:1|fillcolor%3ablue|enc:jpV_uoyHzi%40oJ%60%40giAfjAusAjFw~%40tgEqb%40njDxcCd_B%3Fm%60%40~l%40q}BtsA{aAqb%40_m%40nJmdBfDk_%40nx%40g%60Bfs%40}Tl%60%40co%40g\mw%40%3Fud%40cY

Don't be confused because of the blue background. You've switched lat and lng in coords, the polygon is not placed in london, it's somewhere in the ocean between somalia and seychelles.

I guess the desired result should be this:

http://maps.googleapis.com/maps/api/staticmap?scale=2&size=1000x1000&sensor=false&style=feature%3Alandscape%7Celement%3Aall%7Csaturation%3A-100%7Clightness%3A65%7Cvisibility%3Aon%7C&style=feature%3Apoi%7Celement%3Aall%7Csaturation%3A-100%7Clightness%3A51%7Cvisibility%3Asimplified%7C&style=feature%3Aroad.highway%7Celement%3Aall%7Csaturation%3A-100%7Cvisibility%3Asimplified%7C&style=feature%3Aroad.arterial%7Celement%3Aall%7Csaturation%3A-100%7Clightness%3A30%7Cvisibility%3Aon%7C&style=feature%3Aroad.local%7Celement%3Aall%7Csaturation%3A-100%7Clightness%3A40%7Cvisibility%3Aon%7C&style=feature%3Atransit%7Celement%3Aall%7Csaturation%3A-100%7Cvisibility%3Asimplified%7C&style=feature%3Aadministrative.province%7Celement%3Aall%7Cvisibility%3Aoff%7C&style=feature%3Awater%7Celement%3Alabels%7Cvisibility%3Aon%7Clightness%3A-25%7Csaturation%3A-100%7C&style=feature%3Awater%7Celement%3Ageometry%7Chue%3A0xffff00%7Clightness%3A-25%7Csaturation%3A-97%7C&path=color%3A0044ff%7Cweight%3A1%7Cfillcolor%3Ablue%7Cenc%3A_uoyHjpVoJzi%40giA%60%40usAfjAw~%40jFqb%40tgExcCnjD%3Fd_B~l%40m%60%40tsAq%7DBqb%40%7BaAnJ_m%40fDmdBnx%40k_%40fs%40g%60Bl%60%40%7DTg%5Cco%40%3Fmw%40cYud%40

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top