0

I am getting the xml file by below script But how can I save and access on C# page ? "http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US"

function markicons() {

    InitializeMap();

    var ltlng = [];

    ltlng.push(new google.maps.LatLng(17.22, 78.28));
    ltlng.push(new google.maps.LatLng(13.5, 79.2));
    ltlng.push(new google.maps.LatLng(15.24, 77.16));

    map.setCenter(ltlng[0]);
    for (var i = 0; i <= ltlng.length; i++) {
        marker = new google.maps.Marker({
            map: map,
            position: ltlng[i]
        });

        (function (i, marker) {

            google.maps.event.addListener(marker, 'click', function () {

                if (!infowindow) {
                    infowindow = new google.maps.InfoWindow();
                }

                infowindow.setContent("Message" + i);

                infowindow.open(map, marker);

            });

        })(i, marker);

    }

}

window.onload = markicons; 

"

4

2 回答 2

0

看起来您需要在客户端 javascript 中访问该文件。您需要使用 ajax:这是 jQuery 的示例:

$.ajax({
url: 'http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US',
success: function(resultDocuement){   alert(resultDocuement);         },
dataType: 'json'
});

'resultDocuement' 将包含来自 json 中 URL 的结果

于 2013-06-20T08:41:30.447 回答
0

首先你没有得到一个xml,你有一个json文件,你可以从一个页面保存你的json文件:

    var client = new WebClient();
    client.Headers.Add("User-Agent", "Nobody");
    var response = client.DownloadString(new Uri("http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US"));
    File.WriteAllText(@"c:\logs\yourjson.json", response.ToString());
于 2013-06-20T08:53:05.763 回答