question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google maps API v3 (still tainted with proxy and markers missing)

See original GitHub issue

Hello,

I managed to make this partially work with google maps. I’m also using a proxy I wrote in Ruby (Rails).

Here’s the code of my proxy (it’s very basic and it’s actually a controller action within my application):

class ProxyController < ApplicationController
  def get_image
    url = URI.parse(params[:url] || "")
    callback = params[:callback]

    response = Net::HTTP.start(url.host, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
      http.get url.request_uri
    end

    bin_body = response.body

    base64 = [bin_body].pack("m0")
    responseData = 'data:' + response.header.content_type + ';base64,' + base64

    output = "#{callback}(#{responseData.to_json})"
    send_data output, type: 'application/javascript', disposition: 'inline'
  end
end

I’m pretty sure the proxy is working because I’m getting the same output as the one in node.js.

This is the JS that I use to render the canvas

$("a.export-map").click ->
  html2canvas $("div#map"),
    proxy: "/proxy/get"
    onrendered: (canvas) ->
      console.log(canvas.toDataURL())
  false

Now, It kinda works… I’m attaching the output of the function as well as how it should be.

This is my result: image

This is how it should be: desired

As you can see, some thing are missing. Like the marker and the left side controls.

Also I’m getting between 3 and 4 console errors when I try to convert. The errors are always the same:

Unable to get image data from canvas because the canvas has been tainted by cross-origin data. html2canvas.js?body=1:2735
    safeImage html2canvas.js?body=1:2735
    renderItem html2canvas.js?body=1:2769
    (anonymous function) html2canvas.js?body=1:2819
    _html2canvas.Renderer html2canvas.js?body=1:2562
    options.complete html2canvas.js?body=1:2677
    start html2canvas.js?body=1:2209
    img.onload

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
btouegcommented, Aug 4, 2017

Have you tried setting optimized: false in the markers options?

It will make google maps render every marker as a DOM element, thus enabling html2canvas to find them and render them.

Worked for me.

1reaction
TehNrdcommented, Jul 11, 2020

@btoueg This saved me hours of frustration, thank you! When optimized is set to true google maps will still render the actual dom elements up to a certain number of makers. Was this number is passed, around 200, it will then convert the images to canvas elements that prevent the markers from rendering.

I loop through all of the markers and set optimized to false, grab the screenshot, and then set optimized back to true. It seems to be working well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading Your Maps JavaScript API Application from V2 to V3
The Maps JavaScript API v2 is no longer available as of May 26, 2021. As a result, your site's v2 maps will stop...
Read more >
Google maps marker missing API v3 - Stack Overflow
I have a google map API v3 embed in my website with a custom marker. ... the map area keeping the coordinates, but...
Read more >
Allowing cross-origin use of images and canvas - HTML
As soon as you draw into a canvas any data that was loaded from another origin without CORS approval, the canvas becomes tainted....
Read more >
Untitled
Revlon lipstick 013, Soupe bonne femme, Accepted 2/3/14 still no dd, ... Google maps api not working in chrome, Garmin watches golf, Cancer...
Read more >
CRAN Packages By Name
accelmissing, Missing Value Imputation for Accelerometer Data ... amapGeocode, An Interface to the 'AutoNavi Maps' API Geocoding Services.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found