Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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 数组中包含的对象原型_Javascript_Google Maps Api 3 - Fatal编程技术网

Javascript 数组中包含的对象原型

Javascript 数组中包含的对象原型,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我正在开发一个功能,该功能可以从多个标记中提取lat/lng。函数如下所示。但是,mapData数组中的每个对象都包含本机对象的原型以及lat/lng。我曾玩弄过自己的财产,但运气不好。我是不是做错了什么 function prepareMarkers() { var mapData = []; // All we need from our markers list is the coordinates of the marker and title if it ha

我正在开发一个功能,该功能可以从多个标记中提取lat/lng。函数如下所示。但是,mapData数组中的每个对象都包含本机对象的原型以及lat/lng。我曾玩弄过自己的财产,但运气不好。我是不是做错了什么

    function prepareMarkers() {
    var mapData = [];

    // All we need from our markers list is the coordinates of the marker and title if it has one
    markers.forEach(function(elem, index) {
        mapData.push({
            lat: elem.getPosition().lat(),
            lng: elem.getPosition().lng()
        });
    });

    return mapData;
}

您正在将本机对象放入mapData数组中。就是这样。它是一个物体

    {
        lat: elem.getPosition().lat(),
        lng: elem.getPosition().lng()
    }
所以,它完全按照它应该的方式工作。因为它们是对象,所以它们应该具有来自本机对象原型的方法。这里有你想解决的特殊问题吗?到目前为止,你所描述的一切听起来都是正确的

在阵列中,您可以访问以下内容:

var latitude = mapData[0].lat;
var longitude = mapData[0].lng;

是的,不知道我在担心什么,谢谢你的澄清。