我的代码存在一个小问题,似乎停在JSON文件中的10个列表中
并且JSON文件带有300多条记录,有人请告诉我哪里出错了
样本 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 :(得分:0)
if(!obj.suburb)
你只是试图展示那些没有郊区的人。
它显示直到Johns Landing Camping Ground的所有点 - 它没有显示“Gold Coast 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": ""
},