3

I get from the server an image as json format:

image=iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAA

for the google marker I have to assign an image this way:

  var myImage = "../Content/image.jpeg";

            var markerOptions = {
                position: bound,
                map: map,
                icon: myImage 
            };

How can I convert the json image data into an image google maps accepts?

I have tried this:

 var image = document.createElement('img');
 image.src = "data:image/png;base64" + base64JsonData;

but this result in an error on runtime.

This is the full json which I did not paste here before because of flood preventing...:

image=iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAAABvFaqvAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAYHSURBVDhPJVVbbBxnFf7n8s/OfWavM2t7187GGzuNnditQykx0FiltgQPVCapxUOaQkCCIsRLXpDyCogKeENVJZCoaKUSaEoSMJVoH9wqiWvIxVHcUstkY8d41/buzu7s3G8cq6PRP6Pzn/Od7zvnnzOEl0QIoSgKMIVtx5Q4IY4jiiBQAneI4oNN5AaIppDd++2rv6y3dllV+enPf4EShGg+QVRjv53PZUkSPFHMUNgPHD7FEghRYIN4x0GBj6IARfHBurNdu3WrXns4Wjm8+3grbLcQRXVa+xCr5bI9y6ZRHPiuK/ICj1OQxDVNGiWJ52FJRkC2/r9/L314+Y9vrN25069rSibdzalcHNGyjLqGkk4DX8txRUEkkiSAwF6nK4oCioEp0InB6dqbb929dXN1+QZybU2SRIZhSdKNQ+1I9aO7t3/35lvqxCSisdXpCRktQgSRBC6QBCzkQyEwss33r1177Te/xoGHbEvFVBqTXJIQjh3aVkxTvN73sLXf8vy3F/9OVKooxSIS9xyHRCTlGB0QFbguCL67spKR5YVvvaDyfArFCibZMEg6LSHy8wzVz7PJ3q4axZV0+tw3X+g8WIXKoCQQGBBCQCViRCAsSbW1tRs3Pvps/dPR0dHx48d4FlNxiFFEha5IxSqNxCTQGVzEzJGCdmJw6JWXzqP9PdBOkAQZh4GYVp2eaXba199b1MsD0Gkn8M+++OLwyBFO4DmOlUVBkUU2RSHfK4h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tw0oLQgomoiRJV69edRynVCqBIl3Xm82OoiiQ3/djCAAL8Ko9+m+5PHDmzBlgEQQBcIQVcIE+0evZgsABFvw4QNHGxkatVut2u5VKZX19HdSdPn3a87xLly4Vi0UQPjPzLOxCgs+xoEbwAj2BmQ3XAYppWpIkgDUMY5omIYFhGDs7O0tLS1BsiDl79uz4+LHPg4ECEITCgz/o4Dju/24H7lN8fByxAAAAAElFTkSuQmCC
7
  • 2
    Which error? @HelloWorld Commented Jun 5, 2013 at 10:14
  • I'm looking into it at the moment but I can't even get the data URI to work for a normal image. As for setting it as a Google Marker, it may just take the Data URI directly if it takes the Path the same way. Would need to double check with the specs. Commented Jun 5, 2013 at 10:15
  • 1
    src="data:image/png;base64," +base64JsonData; -- Try this Commented Jun 5, 2013 at 10:16
  • you are missing a comma en.wikipedia.org/wiki/Data_URI_scheme src="data:image/png;base64," Commented Jun 5, 2013 at 10:17
  • now I do not get an error anymore with the "comma" added but still the image is not visible on the map. Commented Jun 5, 2013 at 10:27

1 Answer 1

13
var image = document.createElement('img');
image.src = "data:image/png;base64," + base64JsonData;

For further reading see this link

Sign up to request clarification or add additional context in comments.

1 Comment

Almost exactly 10 years later, and you helped me finally understand binary to blog on Angular 14, etc. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.