Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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_Ajax_Json_Google Maps - Fatal编程技术网

调用javascript对象值给我';未定义';

调用javascript对象值给我';未定义';,javascript,ajax,json,google-maps,Javascript,Ajax,Json,Google Maps,我正在开发一个谷歌地图应用程序,我想从数据库中加载一些标记,并将它们显示在地图上。所以我创建了一个数组并定义了一个像这样的对象 function shop_data(name,latitude,longitude,type) { this.name=name; this.latitude=latitude; this.longitude=longitude; this.type=type; } 然后,我将从ajax请求中检索到的一些数据添加到“s

我正在开发一个谷歌地图应用程序,我想从数据库中加载一些标记,并将它们显示在地图上。所以我创建了一个数组并定义了一个像这样的对象

function shop_data(name,latitude,longitude,type)
    {
    this.name=name;
    this.latitude=latitude;
    this.longitude=longitude;
    this.type=type;
    }
然后,我将从ajax请求中检索到的一些数据添加到“shop_data”对象数组中。数组被定义为“所有商店”

var i=0;
for(var o in data){
var name = data[o].name;
    var type = data[o].type;
var lat = data[o].lat;
var lng = data[o].lng;

all_shops[i]=new shop_data(name,lat,lng,type);
i++
}
然后,当我调用'all_shops[i].name'时,它会给我原样的名称。但当我调用'all_shops[I].lat'或'all_shops[I].lng'时,它会给我'undefined'。我也试着分析lat。这里lat、lng是MySQL数据库中的双变量。 我可以通过调用name、type、lat、lng从接收到的ajax数据中毫无问题地获得lat、lng值。但是当我把它们都放在一个数组中,然后从数组中调用它们时,事情就出了问题。任何帮助都将不胜感激。谢谢

this.latitude=latitude;
this.longitude=longitude;

您有一个简单的复制/粘贴错误。

this.latitude=latitude;
this.longitude=longitude;


您有一个简单的复制/粘贴错误。

您应该从
所有商店[i]
调用
纬度
经度
,而不是
纬度
lng
因为您有这样的
shop\u数据
函数定义

function shop_data(name,latitude,longitude,type)
{
   this.name=name;
   this.latitude=latitude;
   this.longitude=longitude;
   this.type=type;
}
或者,如果要使用
lat
lng
则更改
shop\u数据
功能定义,如

function shop_data(name,latitude,longitude,type)
{
   this.name=name;
   this.lat=latitude;
   this.lng=longitude;
   this.type=type;
}

您应该从
所有商店[i]
呼叫您的
纬度
经度
,而不是
lat
lng
因为您有这样的
shop\u数据
函数定义

function shop_data(name,latitude,longitude,type)
{
   this.name=name;
   this.latitude=latitude;
   this.longitude=longitude;
   this.type=type;
}
或者,如果要使用
lat
lng
则更改
shop\u数据
功能定义,如

function shop_data(name,latitude,longitude,type)
{
   this.name=name;
   this.lat=latitude;
   this.lng=longitude;
   this.type=type;
}

将变量名称更改为匹配,并进行少量清理,可以:

function shop_data(name,latitude,longitude,type){
    this.name=name;
    this.lat=latitude;
    this.lng=longitude;
    this.type=type;
}
以及:


将变量名称更改为匹配,并进行少量清理,可以:

function shop_data(name,latitude,longitude,type){
    this.name=name;
    this.lat=latitude;
    this.lng=longitude;
    this.type=type;
}
以及:


您将纬度定义为“纬度”,所以当然,以“lat”访问它将返回未定义的。哦,不。。。。我真是个白痴。。。。无论如何,谢谢贝尔和平。我得到了它。非常感谢您花时间回答我愚蠢的问题。您将纬度定义为“纬度”,因此当然,将其访问为“lat”将返回未定义的。哦,不。。。。我真是个白痴。。。。无论如何,谢谢贝尔和平。我得到了它。非常感谢你花时间回答我愚蠢的问题。谢谢约格拉,我明白了。太尴尬了。非常感谢Hanks Yograj,我明白了。太尴尬了。谢谢