更新GDownloadUrl()

时间:2011-07-11 09:28:46

标签: javascript

我正在使用带有标记的谷歌地图,我在地图上方有一个搜索表单。我试图让onchange更新GDownloadUrl(),从而缩小页面上加载的标记。

以下是我的尝试:

<script type="text/javascript">
            function load() {
                if (GBrowserIsCompatible()) {
                    var map = new GMap2(document.getElementById("map"));
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                    map.setCenter(new GLatLng(38.85682, -96.943359), 4);
                    var selector = document.getElementById("sport");
var url = "url here ?sport="+selector.options[selector.selectedIndex].value+"";
                    GDownloadUrl(url, function(data) {
                        var xml = GXml.parse(data);
                        var markers = xml.documentElement.getElementsByTagName("marker");
                        for (var i = 0; i < markers.length; i++) {
                            var name = markers[i].getAttribute("name");
                            var address = markers[i].getAttribute("address");
                            var type = markers[i].getAttribute("type");
                            var title = markers[i].getAttribute("title");
                            var id = markers[i].getAttribute("id");
                            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                            parseFloat(markers[i].getAttribute("lng")));
                            var marker = createMarker(point, name, address, type, title, id);
                            map.addOverlay(marker);
                        }
                    });
                }
            }
            </script> 

链接到页面:http://michaelstevens.dyndns.org/athletenation/index.php?option=com_athletenation&view=Events&Itemid=3

1 个答案:

答案 0 :(得分:1)

我明白了,一旦我退后一步并想到我想要做的事情,这很容易:

function changeme(){

  var map; //clears current icons

//get the value of each input:
var e = document.getElementById("sport");
var strUser = e.options[e.selectedIndex].value;

var event = document.getElementById("event");
var strUserevent = event.options[event.selectedIndex].value;

var price = document.getElementById("price");
var strUserprice = price.options[price.selectedIndex].value;

var miles = document.getElementById("miles");
var strUsermiles = miles.options[miles.selectedIndex].value;

var zip = document.getElementById("zip");
var strUserzip = document.getElementById('zip').value;

  xmlurlsport = "?sport="+ strUser +"";
  xmlurlevent = "&event="+ strUserevent +"";
  xmlurlprice = "&price="+ strUserprice +"";
  xmlurlmiles = "&miles="+ strUsermiles +"";
  xmlurlzip = "&zip="+ strUserzip +"";

 var xmlurl = " url here "+xmlurlsport+""+xmlurlevent+""+xmlurlprice+""+xmlurlmiles+""+xmlurlzip+"";


                    var map = new GMap2(document.getElementById("map"));
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                    map.setCenter(new GLatLng(38.85682, -96.943359), 4);


                    GDownloadUrl(xmlurl, function(data) {
                        var xml = GXml.parse(data);
                        var markers = xml.documentElement.getElementsByTagName("marker");
                        for (var i = 0; i < markers.length; i++) {
                            var name = markers[i].getAttribute("name");
                            var address = markers[i].getAttribute("address");
                            var type = markers[i].getAttribute("type");
                            var title = markers[i].getAttribute("title");
                            var id = markers[i].getAttribute("id");
                            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                            parseFloat(markers[i].getAttribute("lng")));
                            var marker = createMarker(point, name, address, type, title, id);
                            map.addOverlay(marker);
                        }
                    });




alert(xmlurl);

}