strange behavior with paths in google maps static image api - google-maps

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=320x320&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

Related

Google Maps API returns zoomed out repeated view of the globe - possible incorrect coordinates?

I'm working on a project where I am showing 8,000+ lat/long coordinates on a Google Map. Works great.
Today I uploaded another 3,000+, and now the Google Map shows a world view of the globe, repeated horizontally, with a lot of gray space on top.
I've looked through the 3,000+ entries, and do not see any where alpha characters, missing lat/long values, etc - something obvious.
The only thing that I can think of is that a lat/long entry is incorrect, and thus the Google Map zoom breaks? Reviewing questions on SO show hacks such as setting minZoom or zoom levels - but I feel that isn't the right path to go across to solve this, since it was working before and something is happening with my new records. I've checked that no pins are on the map outside USA which may cause the entire world view to show.
I'm reaching out to the community to see if anyone smarter than me has a tip or suggestion to help edge case occurrences like this, and/or if my assumption of a wrong lat/long is breaking the Map?
One of your lat/long is incorrect. Instead of Google Maps API failing and alerting, it just breaks the map. I'd advise you to run your locations to confirm decimals exists per each record.

Why are my line colors not showing in my KML file on Google Maps?

I have a KML file from an architect who says he colorized the lines (white, blue, red) and I see the codes in the file itself so I know they are there. The proper colors do display in Google Earth, but NOT in google maps http://lonesomevalley.com/site-map-mapbox/ that I added as a KML layer into MapBox. They also don't display when I bring into the Geojson.io tool so something must be wrong. I see that color is supported by google maps so wondering why it isn't working. Please help! Thanks in advance! My code can be downloaded here: http://evolv.com/lonesome.kml
If I understand the question right, it was the same problem like I had for quit a while. Then someone gave me this quit simple solution.
The colorcodes in kml are in BGR format, while most other formats are the usual RGB format.
The conversion is quit simple: RGB 'ff12dd' will be in BGR 'dd12ff' (R and B just change) but in kml there must always be 'FF' in front, so it will be 'FFdd12ff'
I can't tell you if it's the same issue on your mapbox-implementation(mapbox isn't google maps)
The colors also will not be applied in a google.maps.KmlLayer
The issue seems to be that you've placed the <Style/>'s in <Folder/>'s
When you validate the KML ( http://www.kmlvalidator.com/home ) you'll see that the styles may not be found(and more errors) .
Possible solution( at least related to google-maps): Place the Styles outside of the Folders, as direct childs of <Document/>
Okay after much trial and error working within the KML file, I finally consulted an expert who gave me a simple answer that worked! He said the easiest way to go about changing line colors and weight is through MapBox Editor itself. All you have to do is click on the Data tab, then the 3 horizontal lines button ("hamburger menu drawer icon") to bring up the features. Then you can delete any feature you want from there or click on the feature to change its stroke color and weight. So EASY!!! Just be sure to hit save when done. And there is no Undo if you trash something by mistake so make sure to Save every once in a while and just back out of the project without saving in order to get back something you deleted by mistake.
So all in all I believe that KML files don't bring in the colors of lines correctly to MapBox and therefore need to be corrected through the editor itself.

is it possible that my server doesnt like api v3?

Im not sure how but thats the only conclusion I can come to.
Ive been playing around with placing a marker at a distance along a route, I found Mike Willamsons epoly.js and some example files and started to play around with them but for some reason the exact same code doesnt work on my server.
eg
http://www.geocodezip.com/v3_GoogleEx_directions-waypoints_kmmarkersC.html
is a simple example that drops two markers at 2 different distances along the route.
I simply viewed source, copied the entire code and pasted it into an hmtl file on my server, taking care to create the scripts directory and drop v3_epoly.js into it.
As you can see below, my page however does everything except output those 2 important markers.
http://peg-web.me.uk/map/
Am I missing something fundamental?
I know, this forum isnt for the epoly.js add in but Im trying to establish if my problem is more fundamental ie related to javascript itself.
Those marker icons are referenced with relative URLs, copy the icons onto your server, put them in the same relative location to the HTML page and they will appear.
Or change this line in the createMarker function:
icon: getMarkerImage(color),
To (comment the property out):
// icon: getMarkerImage(color),
(that will make them use the default marker icon)

Custom Placemark symbols used in KML not showing up in Google Maps

This is driving me crazy. I've been developing some simple embedded Google Maps such as the following:
http://publicworks.snoco.org/rdclosures/snocordclosuregmaps.html
This map in particular has several kml overlays but one of them is no longer displaying the custom placemark icons I had developed and specified. The problem KML layer is this:
http://publicworks.snoco.org/RdClosures/SnocoRdClosures4Gmaps.kml
Some time in the last few months, the custom symbols stopped displaying and have been replaced by the default placemark symbol. If you open the KML file in Google Earth, it displays properly. The KML file does validate using KmlValidator.
Through my searches on here, I saw a suggestion about using definitions at the top of the KML file and then using within each Placemark. I made that change to my KML but it did not appear to make any difference (the custom icons are still not displaying).
I realize that KML files get cached on Google's end so if you look at my javascript code, I'm using the dummy parameter trick with my KML URL path to force a refresh of the layer. The other thing I will note is that the content of this KML is not static and it frequently changes.
Any ideas? Because I'm stumped!
THANKS!
Steve
Agreed with fragileninja that something is happening with your images between your server and Google's. The usual suspects are timing out and 404s (or other server errors).
Since the KML layer is actually being rasterized to tiles on Google's servers, the request has a relatively short timeout so the tiles aren't delayed from being sent to the browser. If the icon images aren't returned in that time, usually Maps will render using the default icon (as it's doing here). However, I also have no trouble getting the icons to work when I host them on my own server, and I don't see atrocious loading times when I access your icons directly, so it is strange.
It's possible that your servers are taking a longer than usual time to respond to Google's servers specifically, or even that they're returning some HTTP error to them instead of an image.
Can you check your server logs to see if you can see the requests and if they're returning as expected?
Finally, if there's no problem there, I would suggest filing a bug on the Maps API issue tracker. Make sure to pick the appropriate template from the dropdown list (you might also consider making a simpler test case, like just using your KML file with the KmlLayer example from the docs) . If you do end up filing a bug, please link it here and I'll make sure it's looked at.
It's something to do with how your server is serving up the images. If I host the icons on mine, it works fine, and your other KML files are using icons from maps.google.com, which also works fine.
Since it works in GE, I'm guessing maybe your server is sending the wrong MIME type or something along those lines. I checked with curl and everything looks fine though, so I'm afraid I can't offer any more details than that. Hopefully this helps get you in the right direction. Good luck!

Custom icons in KML occasionally break in Google Maps

So this might be a bit tricky to demonstrate, since the problem only appears occasionally and unpredictably--hopefully the problem shows up when you view this question (or, alternatively, has stopped appearing altogether!).
We have a Google Maps implementation on our site that displays paginated search results on a map. The current page's results appear as regular Google Maps markers (with custom icons--these work fine), but the other search results appear as smaller markers in a KML layer. An example:
http://www.redflagdeals.com/in/verdun/map/
The large markers are squarish pin images; the small markers are coloured dots. Blue and purple markers/dots simply refer to different types of content. In the KML file, we've specified two Styles, one for each content type. Other than the Icon reference, which points to the different pin images, the two elements are exactly the same. Here's an example generated KML file for reference:
http://www.redflagdeals.com/in/verdun/map/?do=map_kml&longitude=-73.56895400000002&latitude=45.457064&order=deal_price&dir=asc&category_filter=0&content_filter=0&tag_filter=0&keyword=&page=1&show=deal%20coupon
Most of the time, our map shows the large and small markers perfectly. Occasionally, though, some or all of the small pins show up without the custom icons, instead reverting to the generic blue Google marker image. Today, the custom minipins that show up in blue are broken, while the purple ones are all fine. Other times, both the blue and purple ones are broken.
The problem usually fixes itself, leaving us clueless as to the cause or the solution. The only theory I have is that we use a CDN to host our marker images, and occasionally we push a new version to the CDN while updating all the filenames simultaneously (as we have CDN version numbers in the URLs for our images). Maybe it's possible Google is requesting one or both of the small pin images right when we're pushing a new CDN version, getting a 404, and giving up immediately. But that would mean Google caches the KML images (or lack thereof) for quite a long time. Other than that, I have no ideas.
Is there anything we can do to prevent this problem from cropping up in the future?
see this post (Comment #4 specifically) explains caching of custom markers
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3864
I've just tested this, the result is the following:
I'm sure Google caches both, the KML-file and the marker-images.
(Of course they do, otherwise they must load the files and create new tiles on every single request )
So when you change any marker-image, you must change the URLs of the marker-images inside the KML-file.
You also must change the URL of the KML-file inside your application(otherwise google will not recognize the modified image-URL's)
It's sufficient to append a random parameter to the URLs