none
Bing Maps Imagery API not working RRS feed

  • Question

  • Trying to download static images here so that the image can later be zipped or printed.

    I have got differing results on different machines and using different piece of code and not sure what is going on here and how the imagery API should be used.

    First case:

    http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.6156352,-122.2043549/12?pp=47.6156352,-122.2043549;;1&pp=47.612441,-122.204533;;2&dcl=1&jsonp=ImageCallBack&key=bing key

    This url when copied in a browser shows the image.

    When try to execute this through code

    function

    CallRestService(request) {

               

    var script = document.createElement("script");

                script.setAttribute(

    "type", "text/javascript");

                script.setAttribute(

    "src", request);

                document.body.appendChild(script);

            }

    I get the following error in the IE debugger window

    <dir>

    SCRIPT1014: Invalid character

    12?pp=47.6156352,-122.2043549;;1&pp=47.612441,-122.204533;;2&dcl=1&jsonp=ImageCallBack&key=line 1 character 5

    I have been able to successful execute the Routing and Geocoding API using the above code.

    I am not sure what the script error could be here.

    I am running this through http://localhost:1000 and I thought it might be about localhost and so changed it to http://machine:1000 but that did not help either.

    Second case

    Another logic for executing the same URL worked. The code copied below.  
               
    var url = "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.6156352,-122.2043549/12?pp=47.6156352,-122.2043549;;1&pp=47.612441,-122.204533;;2&dcl=1&key=

    var retrieveRecordsReq1 = new XMLHttpRequest();

                retrieveRecordsReq1 .open('GET', url, false);
                retrieveRecordsReq1 .setRequestHeader("Content-Type", "text/plain; charset=utf-8");
               
                retrieveRecordsReq1.send(null);
     var res = retrieveRecordsReq1.responseText;

    However even this code works only in compatibility view in IE 9 and IE 10. If you switch off compatibility it wont work.

    What are we missing here and is there a consistent way to get this to work across all browsers including IE, FireFox, Chrome and Safari

    Spent all day getting this to work. There doesn't seem to be any sample code around that would actually show this executed through a jscript.

    Any assistance greatly appreciated.

    Sam

    </dir>

    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, May 15, 2013 12:25 PM

Answers

  • The URL returns and image but you are treating it like it is a JavaScript file. Simple pass the URL as the src property of an img tag on your page and load it like an image.


    http://rbrundritt.wordpress.com

    Wednesday, May 15, 2013 6:06 PM
  • If you want to make a post request then you will need to use something other than the current method you are using to call the service. However, since this is a cross domain request you will likely run into a bunch of headaches. What I have done in the past is created a simple proxy service which simply takes a POST request from JavaScript and then makes the request for the image, then passes it back to JavaScript.


    http://rbrundritt.wordpress.com

    • Marked as answer by Sam - Inogic Tuesday, May 21, 2013 4:56 AM
    Monday, May 20, 2013 8:59 AM

All replies

  • The URL returns and image but you are treating it like it is a JavaScript file. Simple pass the URL as the src property of an img tag on your page and load it like an image.


    http://rbrundritt.wordpress.com

    Wednesday, May 15, 2013 6:06 PM
  • Hi Richard,

    Thanks that did work.

    But I was hoping I could get it to work using the http get/post methods if possible.

    I read further that the puspins parameter could hold a max of 18 pushpins at a time... if more needed uses the http get/post

    If you use HTTP GET method with the following URL templates, you can specify up to 18 pushpins in the URL. If you want to specify more than 18 pushpins, use the HTTP POST method and specify up to 100 pushpins in the body of the HTTP POST request. If you use the HTTP POST method, all pushpins must be in the body of the request and not in the URL, and you must set the Content-Type to “text/plain” and the charset to “UTF-8” in the HTTP header. For a sample request, see the Examples section

    The examples section only has the url provided but not the script code. I am trying to execute the http get/post using one of the pieces of code included in my original request.

    can you please confirm how this could be achieved.

    Background - The application would allow users to do a proximity search which will plot multiple pushpins on the map (there is no limit to the pushpins plotted, based on the data provided). We now looking at providing the ability to print this.

    I am not sure if this could be achieved by setting the URL since you are only allowed to pass upto 10 pushpins in the url parameter.

    Any inputs here.

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, May 16, 2013 3:06 AM
  • Any options here?

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, May 20, 2013 3:48 AM
  • If you want to make a post request then you will need to use something other than the current method you are using to call the service. However, since this is a cross domain request you will likely run into a bunch of headaches. What I have done in the past is created a simple proxy service which simply takes a POST request from JavaScript and then makes the request for the image, then passes it back to JavaScript.


    http://rbrundritt.wordpress.com

    • Marked as answer by Sam - Inogic Tuesday, May 21, 2013 4:56 AM
    Monday, May 20, 2013 8:59 AM
  • thanks for the suggestion. Will give that a try. Sam

    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, May 21, 2013 4:56 AM