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"
我通过下面的脚本获取xml文件,但是如何在c#页面上保存和访问呢?“http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001目的地= 34.052360,-87.62979000000001传感器= 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;
"
”
2 个解决方案
#1
0
It looks like you need to access the file in client javascript. You need to use ajax: Here is example for jQuery:
看起来您需要访问客户机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' will contain the result from the URL in json
“resultDocuement”将包含json格式的URL的结果
#2
0
First you dont are getting a xml, you got a json file anyway you can save your json file with this from a page with this:
首先你没有得到一个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());
#1
0
It looks like you need to access the file in client javascript. You need to use ajax: Here is example for jQuery:
看起来您需要访问客户机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' will contain the result from the URL in json
“resultDocuement”将包含json格式的URL的结果
#2
0
First you dont are getting a xml, you got a json file anyway you can save your json file with this from a page with this:
首先你没有得到一个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());