none
Bing Maps API: appendChild Error when address is incorrect. RRS feed

  • Question

  • Hi we've been facing a problem with bing maps when the address is incorrect. I keep getting the "Uncaught TypeError: Cannot read property 'appendChild' of null veapiDirections.js:5" exception and it wouldn't load the map. Here is an example "18101 Chatsworth St Suite, Granada Hills" instead of "18101 Chatsworth St Suite A, Granada Hills." This address is missing the suite number/letter, so the map wouldn't load and gave me that exception. We tried to do some error handling but we can't since it returns "Site Error" when we use window.onerror which happens if the error is from a different domain. We tried with directionsError and try and catch as well but that didn't help either. Any suggestions?


    • Edited by MishoStAv Friday, July 25, 2014 4:44 PM
    Friday, July 25, 2014 4:19 PM

Answers

  • After some testing I managed to reproduce this. The issue is that you haven't specified a DOM element for the direction instructions to render. When the directions manager can't find your address it tries and lists possible alternatives. Since there is no DOM element specified it ends up throwing an error when trying to display this possible address choices. To get around this add something like this to your code:

    directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });

    You will also need to create a DIV or some other container on your page for this to render. for example:

    <div id='directionsItinerary'></div>

    If you don't want to display this kind of information you can also just hide this div. That said, this would mean the users would be unable to select an alternative choice. I'll also log this as a bug so that this can be better handled by the code in the future.


    Monday, July 28, 2014 1:01 PM

All replies

  • After some testing I managed to reproduce this. The issue is that you haven't specified a DOM element for the direction instructions to render. When the directions manager can't find your address it tries and lists possible alternatives. Since there is no DOM element specified it ends up throwing an error when trying to display this possible address choices. To get around this add something like this to your code:

    directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });

    You will also need to create a DIV or some other container on your page for this to render. for example:

    <div id='directionsItinerary'></div>

    If you don't want to display this kind of information you can also just hide this div. That said, this would mean the users would be unable to select an alternative choice. I'll also log this as a bug so that this can be better handled by the code in the future.


    Monday, July 28, 2014 1:01 PM
  • Thank you. We will use your suggestion and let you know if it helped
    Monday, July 28, 2014 10:11 PM
  • This certainly helped us with the error. Thank you.
    Tuesday, August 19, 2014 1:11 PM