我在我的网站上有一个Google地图界面,允许人们放置和放置各种自定义标记等。如何保存自定义的Google地图(API)?
有没有什么方法可以让人们保存这些?或者将它们复制到用户可以访问的网站中的唯一链接上?
我在我的网站上有一个Google地图界面,允许人们放置和放置各种自定义标记等。如何保存自定义的Google地图(API)?
有没有什么方法可以让人们保存这些?或者将它们复制到用户可以访问的网站中的唯一链接上?
我觉得你可以把它们保存在你的数据库中,然后下一个用户登录,就可以从数据库加载数据。
//the locations is the places user defined.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
icon: "the img user defined"
});
});
您还可以使用localStorage和JSON将对象保留在用户的设备中。你可以试试这个代码:
var whatYouWhantToKeep={};
whatYouWhantToKeep.position.lat=marker.getPosition().lat;
whatYouWhantToKeep.position.lng=marker.getPosition().lng;
whatYouWhantToKeep.icon=yourIcon.src;
localStorage.setItem ('aSpecialKey', JSON.stringify(whatYouWhantToKeep));
并得到之后,你想保持你的重点是什么:
var whatYouWhantToKeep = JSON.parse (localStorage.getItem ('aSpecialKey'));
你必须使用JSON,因为localStorage的只接受字符串。