DEV Community

IT Solutionist, Specialist
IT Solutionist, Specialist

Posted on • Edited on

1

How to convert a image from Google Map(Div)?

1.
Hello. Thanks for reading my article in advance.
As you can see above picture, I have displayed a map using Google Map API.
I want to convert a image from that google map using JavaScript.
Who is Someone expert in this part?
Let's discuss in a detail.
Thanks
2.
I have got a solution.
We can use html2canvas library.

html2canvas(document.getElementById("[your map id]"), {
    useCORS: true,
}).then(function(canvas) {
    var img = canvas.toDataURL("image/jpeg");
    var image = new Image();
    image.src = img;
    document.getElementById("[div to display an image]").appendChild(image);
});
Enter fullscreen mode Exit fullscreen mode

It just displays the google map as an image.
Thanks

Top comments (3)

Collapse
 
aarone4 profile image
Aaron Reese

Use stack overflow if you need help. Use DEV to demonstrate the solution when you have one

Collapse
 
it718 profile image
IT Solutionist, Specialist

Hello, Aaron. Thanks for your messaging.

Collapse
 
aarone4 profile image
Aaron Reese

Nice. I'll be using that.

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay