Javascript 在JSON文件中调用位置数据类型
我正在使用GoogleMapAPIv3,我的代码通过jQuery从JSON文件调用Javascript 在JSON文件中调用位置数据类型,javascript,jquery,json,google-maps,Javascript,Jquery,Json,Google Maps,我正在使用GoogleMapAPIv3,我的代码通过jQuery从JSON文件调用 $.getJSON("/temp/google_maps/json/google_map.json", {}, function(data){ $.each(data.location, function(i, item){ $("#markers").append('<li><a href="#" rel="' + i + '">' + item.
$.getJSON("/temp/google_maps/json/google_map.json", {}, function(data){
$.each(data.location, function(i, item){
$("#markers").append('<li><a href="#" rel="' + i + '">' + item.title + '</a></li>');
var marker = new google.maps.Marker({
position: new google.maps.LatLng(item.lat, item.lng),
map: map,
title: item.title
});
arrMarkers[i] = marker;
var infowindow = new google.maps.InfoWindow({
content: "<h3>"+ item.title +"</h3><p>"+ item.description +"</p>"
});
arrInfoWindows[i] = infowindow;
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
});
});
相反,如果前一个:
{
"location": [
{
如何更改jQuery以调用此数据集?任何帮助都将不胜感激。谢谢。除非我弄错了,否则您只是将data.location更改为data.data,例如:
我也是这么想的,但不,不幸的是,这不起作用。它就像更改位置->数据一样简单。我一定是在某个地方把它搞糟了。你说得对,就是这么简单。谢谢你的帮助。
{
"TYPE" : ["location"], "DATA" :[
{
{
"location": [
{
$.getJSON("/temp/google_maps/json/google_map.json", {}, function(data){
$.each(data.DATA, function(i, item){
$("#markers").append('<li><a href="#" rel="' + i + '">' + item.title + '</a></li>');
var marker = new google.maps.Marker({
position: new google.maps.LatLng(item.lat, item.lng),
map: map,
title: item.title
});
arrMarkers[i] = marker;
var infowindow = new google.maps.InfoWindow({
content: "<h3>"+ item.title +"</h3><p>"+ item.description +"</p>"
});
arrInfoWindows[i] = infowindow;
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
});
});