none
I would like to call Bing Map REST API using jquery http post in MVC ? how can I do that ? RRS feed

  • Question

  • I would like to call Bing Map REST API using jquery http post in MVC . from the jquery ajax I will post pushpin information then the bing url will give the respose as image , I would like to get the url and will add src to the image control.


    Tuesday, November 18, 2014 1:00 PM

Answers

  • If you just want a static map image then you can use the Bing Maps REST imagery service to create a URL and set it as the source of an image tag. No need for jQuery. http://msdn.microsoft.com/en-us/library/ff701724.aspx

    If you want to use jQuery you will need to use jsonp as this would mean you are making a cross domain request. For example:

    function downloadJson(request, callback) {
        $.ajax({
            url: request,
            dataType: "jsonp",
            jsonp: "jsonp",
            success: function (r) {
                callback(r);
            },
            error: function (e) {
                alert(e.statusText);
            }
        });
    }


    http://rbrundritt.wordpress.com

    Tuesday, November 18, 2014 2:33 PM
  • Browsers don't let JavaScript do cross domain POST requests with JSONP. There are some hacks to get around this but they don't work on all browsers. One method to get around this that will work with all browsers is to create a proxy service and host it on your domain. The proxy service would take your POST request and make it from server side which would work. Your proxy service would then feed back the response to the browser. This likely is more work than needed as you can simply load the data on an interactive map in less time it would take to do the proxy request.

    Note that it is much better (for performance and cost of service) to use an interactive map and update the data on it then to update static images. Very rarely do I recommend using static images as an interactive map tends to offer a better user experience and in most cases generates a lot less transactions.


    http://rbrundritt.wordpress.com

    Wednesday, November 19, 2014 12:25 PM
  • I've put together a code sample of how to do this here: https://code.msdn.microsoft.com/POST-requests-to-Bing-Maps-c056575a

    http://rbrundritt.wordpress.com

    Thursday, November 27, 2014 1:40 PM

All replies

  • If you just want a static map image then you can use the Bing Maps REST imagery service to create a URL and set it as the source of an image tag. No need for jQuery. http://msdn.microsoft.com/en-us/library/ff701724.aspx

    If you want to use jQuery you will need to use jsonp as this would mean you are making a cross domain request. For example:

    function downloadJson(request, callback) {
        $.ajax({
            url: request,
            dataType: "jsonp",
            jsonp: "jsonp",
            success: function (r) {
                callback(r);
            },
            error: function (e) {
                alert(e.statusText);
            }
        });
    }


    http://rbrundritt.wordpress.com

    Tuesday, November 18, 2014 2:33 PM
  • Hi Ricky,

    Thank you very much  for your reply.

    As you said I can use static map Image service but there is a limitation for static map url it doesn't take more than 18 pushpins information in the url.

    My requirement is I need to post (upto 100 pushpins)all the pushpin data using jquery to bing static map url.I read in the microsoft bing api documentation it is possible by httppost 

    Please help

    Thanks

    Ravikumar.N

    Wednesday, November 19, 2014 9:26 AM
  • Browsers don't let JavaScript do cross domain POST requests with JSONP. There are some hacks to get around this but they don't work on all browsers. One method to get around this that will work with all browsers is to create a proxy service and host it on your domain. The proxy service would take your POST request and make it from server side which would work. Your proxy service would then feed back the response to the browser. This likely is more work than needed as you can simply load the data on an interactive map in less time it would take to do the proxy request.

    Note that it is much better (for performance and cost of service) to use an interactive map and update the data on it then to update static images. Very rarely do I recommend using static images as an interactive map tends to offer a better user experience and in most cases generates a lot less transactions.


    http://rbrundritt.wordpress.com

    Wednesday, November 19, 2014 12:25 PM
  • I've put together a code sample of how to do this here: https://code.msdn.microsoft.com/POST-requests-to-Bing-Maps-c056575a

    http://rbrundritt.wordpress.com

    Thursday, November 27, 2014 1:40 PM