jQuery 和谷歌地图 JSON

发布于 2025-01-07 20:33:39 字数 1686 浏览 1 评论 0原文

我的代码遇到了一个小问题,它似乎停在 JSON 文件中的 10 个列表处

,并且 JSON 文件返回了 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);
         }
    });

}

I am having a small issue with my code it seems to stop at 10 listings in the JSON file

and the JSON file comes back with 300+ records would someone please tell me where I have gone wrong

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);
         }
    });

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2025-01-14 20:33:39
 if(!obj.suburb)

你只是想展示那些没有郊区的。

它显示直到约翰登陆露营地的所有点 - 它不显示“黄金海岸直升机之旅”。

也许是 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": ""
},
 if(!obj.suburb)

You are only trying to show the ones without a suburb.

It displays all points up until Johns Landing Camping Ground - it does not show " Gold Coast Helitours ".

Perhaps an issue with the leading and trailing spaces in the 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": ""
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文