BING maps cross-domain (CORS) RRS feed

  • Question

  • Hello,

        I am using the Bing map rest api to get a static map. Currently I am building the url and is setting the img src to the url like so

     $(".map").attr("src",  "https://dev.virtualearth.net/REST/v1/Imagery/Map/"+mapImagery+"/" + lat + "," + long + "/"+zoomLvl+"?pp=" + lat + "," + long + ";64&key=" + store("bingMapSessionId"));

    The above method works fine. What I would like to do is that instead of setting the url directly, I want to use the jquery ajax to create the url and pass the data in like this

             url: "https://dev.virtualearth.net/REST/v1/Imagery/Map/" + mapImagery + "/" + lat + "," + long + "/" + zoomLvl,
             data: {                                                      
                    pushpin: lat + "," + long + ";64",
                    key: store("bingMapSessionId")
              success: function (data) {
                     $(".map").attr("src", "the img return");
              error: function (e) {
                      window.console && console.log(e);

    The problem is that I am getting a  XMLHttpRequest .... required Cross Origin Resource Sharing (CORS).

    and the error Origin https//:...net not found in Access-Control-Allow-Origin header. I was wondering if the bing map tile are served with CORS permission? Or is there an alternative to getting the map with out directly setting the src to the url. I am fully aware of the AJAX map control that is available, but that counts as a billable transaction every time the control loads, and I did not require the interactivity, just the static map.

    Monday, August 18, 2014 11:43 PM


  • The CORS issue is because you are trying to access a service that is on a different domain. When you do this using the $.ajax function you have to use jsonp. That said, you really should just load the image into a src attribute of an image, there is no reason to use the $.ajax method. Here is some more info on loading images using jQuery: http://stackoverflow.com/questions/4285042/can-jquery-ajax-load-image


    Tuesday, August 19, 2014 10:54 AM