Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
Jquery google.maps.marker位置错误(在json中嵌套google.maps.latLng对象)_Jquery_Json_Google Maps Api 3 - Fatal编程技术网

Jquery google.maps.marker位置错误(在json中嵌套google.maps.latLng对象)

Jquery google.maps.marker位置错误(在json中嵌套google.maps.latLng对象),jquery,json,google-maps-api-3,Jquery,Json,Google Maps Api 3,我收到以下错误,似乎无法理解嵌套在某些json中的google.maps.latLng对象导致错误的原因,特别是: 错误:属性的值无效:(-19.24054258393452,148.15044705312494) 有人知道为什么这段代码会导致错误吗?当I console.log json.markers[n].latLng firebug声明它是一个google.maps.latLng对象时,尽管当它作为错误的一部分包含时,它清楚地表示为.toString()输出(不确定这是否仅仅是因为错误消

我收到以下错误,似乎无法理解嵌套在某些json中的google.maps.latLng对象导致错误的原因,特别是:

错误:属性的值无效:(-19.24054258393452,148.15044705312494)

有人知道为什么这段代码会导致错误吗?当I console.log json.markers[n].latLng firebug声明它是一个google.maps.latLng对象时,尽管当它作为错误的一部分包含时,它清楚地表示为.toString()输出(不确定这是否仅仅是因为错误消息是字符串)

在我一直在开发的jQuery Google Maps V3 API插件上,我使用了以下两种方法。这里有一些片段,我没有包括完整的代码,因为它只会使文章变得杂乱无章。为了清晰起见,我硬编码了一些json,在我完成的插件中,它将通过ajax调用检索

在我的插件的init方法中:

    // Request list of markers and return the json object
var markers = methods.requestMarkers();

// Place the markers
methods.placeMarkers(markers);
作为单独的方法:

requestMarkers : function () {

    return {"markers":[{"id":["7"],"latLng":[new google.maps.LatLng(-19.240542583932452, 148.15044705312494)]},{"id":["8"],"latLng":[new google.maps.LatLng(-28.0497654, 153.43591700000002)]}]}
},

placeMarkers : function ( json ) {

    if (json.markers.length > 0) {

        var markers = new Array();

        for(var n=0; n < json.markers.length; n++){ 

            markers[n] = new google.maps.Marker({
                map         : methods.map,
                position    : json.markers[n].latLng
            });
        }
    }
}
requestMarkers:function(){
返回{“markers”:[{“id”:[“7”],“latLng”:[new google.maps.latLng(-19.240542583934521948.15044705312494)],{“id”:[“8”],“latLng”:[new google.maps.latLng(-28.04976541533.435970000002)]}
},
placeMarkers:function(json){
如果(json.markers.length>0){
var markers=新数组();
对于(var n=0;n

可以找到完整的代码

调用LatLng将始终返回LatLng对象,并且在提供错误的参数时也是如此。 参数当前是一个包含1个LatLng对象的数组,因此必须将位置设置为

json.markers[n].latLng[0] 
与github代码相关:
requestMarkers函数(使用AJAX代码)不会返回任何内容,因此标记将不包含json响应。调用
placeMarkers()
内部
done()


回答得很好,马上解决了问题。还感谢您在Github上多做了一点工作并检查了代码!干杯
requestMarkers : function () {

$.ajax({
type: "get",
url: methods.options.ASSOCIATED,
dataType: "json"
}).done(function( json ) {
if (json.markers.length > 0) {
methods.placeMarkers(json);
}
});


     }