我使用asp.net web表单并希望在bing map上插入图钉。我使用jquery ajax调用来获取照片列表,其中我保持其他属性中的经度和纬度。
HTML:
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
<div style="width: 100px;">
<div style="float: left; width: 700px">
<asp:Panel ID="pnlMap" runat="server" Style="position: absolute; width: 600px; height: 450px;" />
</div>
</div>
网络方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public static IEnumerable<Photo> GetAllVisiblePhotos()
{
using (SqlConnection conn = new SqlConnection( ... return photos;
它真的会返回照片列表。
JavaScript函数是:
function GetPhotos() {
$.support.cors = true;
try {
$.ajax({
url: 'Default.aspx/GetAllVisiblePhotos',
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: DisplayPics,
error: OnError
});
}
catch (err) {
alert(err.message);
}
}
function DisplayPics(response) {
var location;
var pin;
$.each(response, function (index, photo) {
location = new Microsoft.Maps.Location(photo.Latitude, photo.Longitude);
pin = new Microsoft.Maps.Pushpin(location);
pin.Title = photo.Title;
pin.ID = photo.PhotoID;
dataLayer.push(pin);
});
}
但我没有在地图上获得任何图钉。有什么问题?
答案 0 :(得分:1)
响应可从response.d获得,因此更改
subGroupArrayResult is [695,696,697,698,1070,1071,1072,1073,1074,1075,1076,1368,1409,1526,1628,1781,2067,2068,2106,2107,2159]
arraySpeciesIDResult is [699,836,1266,1281,1426,1447,1474,1784,699,836,1266,1314,1426,1447,1474,1764,1784,1905,699,836,1266,1314,1426,1447,1474,1784,699,836,1266,1426,1447,1474,1784,699,836,1266,1426,1447,1474,1784,699,836,1426,1447,1474,1784]
new Array is ["[", "6", "9", "5", ",", "6", "9", "6", ",", "6", "9", "7", ",", "6", "9", "8", ",", "1", "0", "7", "0", ",", "1", "0", "7", "1", ",", "1", "0", "7", "2", ",", "1", "0", "7", "3", ",", "1", "0", "7", "4", ",", "1", "0", "7", "5", ",", "1", "0", "7", "6", ",", "1", "3", "6", "8", ",", "1", "4", "0", "9", ",", "1", "5", "2", "6", ",", "1", "6", "2", "8", ",", "1", "7", "8", "1", ",", "2", "0", "6", "7", ",", "2", "0", "6", "8", ",", "2", "1", "0", "6", ",", "2", "1", "0", "7", ",", "2", "1", "5", "9", "]"]
要
$.each(response, function (index, photo) {