Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSON';将GMap标记的本地存储数组解析为非标记_Javascript_Json_Google Maps Api 3 - Fatal编程技术网

Javascript JSON';将GMap标记的本地存储数组解析为非标记

Javascript JSON';将GMap标记的本地存储数组解析为非标记,javascript,json,google-maps-api-3,Javascript,Json,Google Maps Api 3,我已经问了很多关于我现在正在进行的项目的问题,并且遇到了另一堵墙。我在localStorage中存储了一组Google地图标记,作为存储用户搜索历史的一种方法。当我通过解析和反向循环将数据从localStorage中提取出来时,它们似乎不再是“标记”对象。尽管如此,我仍然看到了我应该看到的大多数值(即纬度和经度(只是它们没有真正命名) 这是我的密码: var markers = []; var cache = localStorage.getItem("searchHistory"); test

我已经问了很多关于我现在正在进行的项目的问题,并且遇到了另一堵墙。我在localStorage中存储了一组Google地图标记,作为存储用户搜索历史的一种方法。当我通过解析和反向循环将数据从localStorage中提取出来时,它们似乎不再是“标记”对象。尽管如此,我仍然看到了我应该看到的大多数值(即纬度和经度(只是它们没有真正命名)

这是我的密码:

var markers = [];
var cache = localStorage.getItem("searchHistory");
testCache = JSON.retrocycle(JSON.parse(cache));
for(i = 0; i < testCache.length; i++)
{
    newMarker = new google.maps.Marker({
        map: map,
        title: //what to do here?
        position: //what to do here?
    });
    markers.push(newMarker);
}
//On places_changed create new marker for location
addListenerToMarker(map,marker);
if(!markerExistsInMarkers(marker,markers))
{
    markers.push(marker);
    localStorage.setItem("searchHistory",JSON.stringify(JSON.decycle(markers)));
}
这本应该对某人有用,但对我来说却成了NaN

以及:


不起作用,因为它不再是标记对象。如何访问testCache中的字段,使其返回我想要的内容?

缓存数组是什么样子的?它是如何创建的?看起来,在很大程度上,是一个庞大的乱码文本数组。它是通过初始代码块底部的localStorage.setItem行创建的。您需要保存创建标记的原始数据,并将其传递给标记构造函数,就像标记以前从未存在过一样。因此,请不要保存标记对象,而是保存我将用于构建标记的信息?嗯,您建议只将相关信息复制到localStorage中,而不是将标记对象本身复制到localStorage中,这种做法非常有效。谢谢
position: new google.maps.LatLng(testCache[i][1],testCache[i][2])
position: testCache[i].position