Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take the screenshot of part of Google Maps use JavaScript

On my page, there is a container which use Google Maps API to display a map, there is a button below it, user can drag the map to a position, then click the button, I'd like to take the screenshot of the map displayed in the container now and show it in a canvas. Is it possible to do this with pure JavaScript?

Just need to support Chrome

like image 922
wong2 Avatar asked Jul 21 '12 08:07

wong2


People also ask

How do you take a snippet from Google Maps?

Open the Google Maps app on your Android phone or tablet. Browse the app to find the area you want to capture. When you're ready to take a screenshot, press the Power and Volume Down buttons together at the same time. The screenshot should be automatically generated and saved in a Screenshots folder in your Gallery.

Can you take images from Google Maps?

Note that we cannot provide high-resolution or vector screen captures of Google Maps; however, you may use Google Earth Pro or Earth Studio on desktop to save and print high-resolution JPEGs. Images can be exported up to 4K.


1 Answers

It will be hard to do without browser support. But you can use Google Static Maps API: https://developers.google.com/maps/documentation/staticmaps/

Example: https://developers.google.com/maps/documentation/staticmaps/#quick_example


There is some projects to draw HTML DOM to canvas:

  • HTML2Canvas: http://html2canvas.hertzen.com/index.html
  • jsFeedback: http://hertzen.com/experiments/jsfeedback/

You can also integrate javascript with some server-side solution (using webkit) for example phantomjs

Code example: (read more here)

var page = require('webpage').create();

page.open('http://www.google.com', function() {

    page.viewportSize = {width: 1024, height: 768};
    page.render('screenshot.png');
    phantom.exit();
});

If you need only chrome solution for specific range of users you can write your own chrome extension to do this: Taking screenshot using javascript for chrome extensions

like image 92
rogal111 Avatar answered Oct 11 '22 17:10

rogal111