2012-02-23 74 views
0

我有我的代碼一個小問題它似乎停止在JSON文件jQuery和谷歌地圖JSON

和JSON文件10名列表回來,有300多個記錄會有人請告訴我哪裏有出了錯

DEMO http://realcashback.com.au/development/maps.php

var map; 
var businessaddress; 
var marker; 

function initialize() { 
    var myOptions = { 
     zoom: 1, 
     center: new google.maps.LatLng(-37.810013, 144.962683), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
     map = new google.maps.Map(document.getElementById('map_canvas'), 
      myOptions); 

    getlocations(); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 


function getlocations(){ 
    $.getJSON('http://realcashback.com.au/development/system/classes/core.php?task=listmyleads', function(data) { 

      $.each(data, function(i, obj) { 
      businessname = obj.TradingName; 
      if(!obj.suburb) 
      { 
      businessaddress = obj.street+", "+obj.suburb+" "+obj.state+" "+obj.postcode; 

      showAddress(businessaddress,businessname); 

      } 
      }); 

    }); 
} 



function showAddress(address,name) { 
    //alert(address); 
    var geocoder = new google.maps.Geocoder(); 
     geocoder.geocode({'address': address}, function(results, status) { 
      if(status == google.maps.GeocoderStatus.OK) { 
      latlngCity = results[0].geometry.location; 
      // alert(latlngCity); 
      marker = new google.maps.Marker({ 
      position: latlngCity, 
       title:name 
      }); 

      // To add the marker to the map, call setMap(); 
      marker.setMap(map); 
     } 
    }); 

} 

回答

0
if(!obj.suburb) 

你只是試圖表明沒有郊區的人。

它顯示所有點直到約翰斯登陸露營地 - 它不顯示「黃金海岸Helitours」。

也許與TradingName中的前導和尾隨空格問題?

{ 
    "TradingName": "Johns Landing Camping Ground", 
    "customer_id": "2039", 
    "storeid": "1", 
    "storename": "", 
    "phone": "0754471806", 
    "street": "Johns Rd", 
    "suburb": "", 
    "state": "QLD", 
    "long": "", 
    "lat": "", 
    "postcode": "4565", 
    "description": "" 
}, 
{ 
    "TradingName": " Gold Coast Helitours ", 
    "customer_id": "2174", 
    "storeid": "1", 
    "storename": "", 
    "phone": "0755918457", 
    "street": "Mirage Heliport, Seaworld Drv", 
    "suburb": "", 
    "state": "QLD", 
    "long": "", 
    "lat": "", 
    "postcode": "", 
    "description": "" 
},