0

I work with asp.net web form and want insert pushpins on bing map. I use jquery ajax call to obtain list of photos where i keep longitude and latitude among the others properties.

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>

Web Method:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
    public static IEnumerable<Photo> GetAllVisiblePhotos()
    {
        using (SqlConnection conn = new SqlConnection( ... return photos;

and it realy returns list of photos.

JavaScript functions are:

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

But I don't get any pushpin on the map. What is wrong?

1 Answer 1

2

Response is available from response.d so change

$.each(response, function (index, photo) {

To

$.each(response.d, function (index, photo) {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.