Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a custom Google Map (API)?

I have a Google Maps interface on my website which allows people to drop and place various custom markers etc.

Is there any way of allowing people to save these? or for them to be copied onto a unique link in the website that the user can access?

like image 546
MRDJR97 Avatar asked Jun 11 '26 04:06

MRDJR97


1 Answers

You can also use localStorage with JSON to keep objects in the user's device. You can try this code:

var whatYouWhantToKeep={};
whatYouWhantToKeep.position.lat=marker.getPosition().lat;
whatYouWhantToKeep.position.lng=marker.getPosition().lng;
whatYouWhantToKeep.icon=yourIcon.src;
localStorage.setItem ('aSpecialKey', JSON.stringify(whatYouWhantToKeep));

And after get what you wanted to keep with your key:

var whatYouWhantToKeep = JSON.parse (localStorage.getItem ('aSpecialKey'));

You have to use JSON because localStorage accept only strings.

like image 197
SphynxTech Avatar answered Jun 13 '26 18:06

SphynxTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!