So, I use Google maps, and I get a snapshot, so it looks like
<img id="staticMap" src="http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap &markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318 &markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false">
I need to save it. I found this:
function getBase64FromImageUrl(URL) { var img = new Image(); img.src = URL; img.onload = function() { var canvas = document.createElement("canvas"); canvas.width = this.width; canvas.height = this.height; var ctx = canvas.getContext("2d"); ctx.drawImage(this, 0, 0); var dataURL = canvas.toDataURL("image/png"); alert(dataURL.replace(/^data:image\/(png|jpg);base64,/, "")); }; }
But I get this problem:
Uncaught SecurityError: Failed to execute 'toDataURL' in 'HTMLCanvasElement': infected canvases may not be exported.
I was looking for corrections. I found a sample here How to use CORS , but still I can't link these two code snippets to make it work. Maybe I'm doing it wrong, and is there an easier way to do this? I am trying to save this drawing in order to transfer data to my server. So maybe someone did something like this and knows how to make .toDataURL() work the way I need it?
javascript cors canvas
user3074343 Dec 6 '13 at 12:45 2013-12-06 12:45
source share