I’m trying to get a static image of a hiking trail from google maps static image API, and I’m seeing some strange behavior. Sometimes, it works pretty well and then other times, it either doesn’t show the path at all or it renders it in a strange way.
Here’s an example of a path which doesn’t show-up the way I’d expect: jagged path
When I build a KML from these same coordinates, everything shows-up just the way that I would expect. But when it’s sent to the static images API, something’s getting mixed-up.
I’ve played around with adjusting the center of the map and the zoom with no noticeable effect. In order to fit within the URL character limit, I had to cut down on the number of coordinates in the path. I’ve tried adjusting the number of points in the path, but I still get a weird, jagged path instead of the one I see from my KML file.
I’ve also tried to remove coordinates from the above URL until I can find the culprit, but then I run into a different issue. Try this image: no points at all. You’ll notice that the path doesn’t show at all in this image.
Sometimes, the call works just fine (I don’t get the granularity I’d like since I have to trim coordinates to with within the URL length limit – but I can live with that). You can see an example here: working example
What’s going on? Am I making some simple mistake that I can’t see or is this something on google’s end? Thanks!
I figured it out. I wasn’t escaping the URL correctly. I skimmed through the API site too quickly (found here) and when I went back and looked through the guide again, I noticed some things that I missed the first time. I was using the python url escape function which was not escaping the parts which needed escaping and escaping things which didn’t need to be escaped.
Here’s an example of a working path:
http://maps.googleapis.com/maps/api/staticmap?format=jpg-baseline&maptype=terrain&size=320×320&sensor=true&path=color:0xff0000ff%7Cweight:2%7C34.680923,-83.998035%7C34.682763,-83.996703%7C34.684612,-83.995759%7C34.685855,-83.994969%7C34.687478,-83.993794%7C34.689339,-83.99301%7C34.691484,-83.992649%7C34.693114,-83.991636%7C34.695631,-83.991983%7C34.697488,-83.990639%7C34.698856,-83.988732%7C34.700114,-83.986356%7C34.701881,-83.985913%7C34.703546,-83.98486%7C34.705588,-83.984205%7C34.707439,-83.985204%7C34.709409,-83.98474%7C34.710815,-83.982891%7C34.713098,-83.982932%7C34.715471,-83.981058%7C34.715643,-83.97896%7C34.716061,-83.976655%7C34.718408,-83.975622%7C34.718576,-83.972885%7C34.720504,-83.972258%7C34.722156,-83.970446%7C34.723245,-83.970965%7C34.724158,-83.968403%7C34.725936,-83.96585%7C34.727591,-83.963934%7C34.729219,-83.962787%7C34.730165,-83.960224%7C34.730464,-83.957465%7C34.731384,-83.954936%7C34.733571,-83.952937%7C34.735248,-83.951872%7C34.736235,-83.94911%7C34.738577,-83.94717%7C34.740465,-83.946156%7C34.741132,-83.943978%7C34.743225,-83.944512%7C34.745393,-83.943994%7C34.742783,-83.942916%7C34.742451,-83.941822%7C34.741552,-83.940703%7C34.740811,-83.939462%7C34.74023,-83.937804%7C34.738605,-83.936371%7C34.736056,-83.935923%7C34.734862,-83.935931%7C34.736535,-83.934433%7C34.737494,-83.932963%7C34.738196,-83.931812%7C34.737864,-83.9307%7C34.735883,-83.930629%7C34.735412,-83.928034%7C34.736785,-83.925242%7C34.737286,-83.922985%7C34.735846,-83.918937