none
Problem initializing map for windows store app 8.1 & JavaScript

    Question

  • What once worked for windows store apps in 8.0 does not when creating a new project in 8.1

    TypeError: Unable to get property 'replace' of undefined or null reference.

    I dont get past  _map = new Microsoft.Maps.Map(document.getElementById("map-container"), config.mapOptions);

    Saturday, October 19, 2013 11:53 PM

Answers

  • crap, i forgot to add Microsoft.Maps.loadModule('Microsoft.Maps.Map') 

    but to be fair, thats kinda silly way to initialize the map when it should work by calling..

    new Microsoft.Maps.Map(

    because thats how you do it with google maps:

    _map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

    So it has the exact same initialization as google maps but with some random extra step!?

    *edit* Also would like to mention that the sample code for windows store apps has not been updated to 8.1

    http://code.msdn.microsoft.com/Bing-Maps-SDK-for-Metro-31b378eb

    Wednesday, October 30, 2013 4:50 AM
  • The line Microsoft.Maps.loadModule('Microsoft.Maps.Map') doesn't initialize the map, it loads in the Bing Maps module/code base. This is done to ensure that no Bing Maps related code is run before the full Bing Maps code base is loaded. The web version of Bing Maps doesn't need to do this as the browser already prevents this from happening as it is generally not as asynchronous as Windows 8 when it comes to loading in JavaScript files.

    http://rbrundritt.wordpress.com

    Wednesday, October 30, 2013 8:57 AM
    Owner

All replies

  • Put a try to catch around the function that is calling the property replace.

    http://www.w3schools.com/js/js_errors.asp

    Sunday, October 20, 2013 6:16 PM
  • i did, map doesnt initialize and this is the error
    Sunday, October 20, 2013 9:28 PM
  • Additionally, i receive this in the javascript console:

    "The method Windows.ApplicationModel.Resources.Core.ResourceManager.get_DefaultContext has been deprecated. DefaultContext may be altered or unavailable for releases after Windows 8.1. Instead, use ResourceContext.GetForCurrentView."

    I've tried uninstalling the SDK and re-installing but that doesnt help.

    Bing Maps SDK for win 8.1 v1.313.825.0

    Visual Studio Express 2013 for Windows

    Sunday, October 20, 2013 9:44 PM
  • I tried to repro using express 2013 & 8.1 SDK, no repro for me. Could you please send some additional details, what you are passing in map options?


    MSFT
    Hemant Goyal

    Wednesday, October 23, 2013 6:25 PM
  • even if i just put:

    var map = new
    Microsoft.Maps.Map(document.getElementById('mapdiv'),{credentials:'my credentials',center: new Microsoft.Maps.Location(47.60, -122.33),zoom:10});     

    I downloaded vs ultimate and the problem is still there.


    Looks like it might be an issue with Windows Library for JavaScript 2.0 + bing maps sdk?
    • Edited by glue24 Sunday, October 27, 2013 5:41 PM
    Sunday, October 27, 2013 5:34 PM
  • Do you have a div on your HTML page that has an id of mapdiv or map-container? I ran into the same error message you had today when I accidently misspelled the id of the div for my map. This resulted in the document.getElementById method passing null into the Microsoft.Maps.Map method and the same error message you referenced appears.

    http://rbrundritt.wordpress.com

    Sunday, October 27, 2013 7:08 PM
    Owner
  • crap, i forgot to add Microsoft.Maps.loadModule('Microsoft.Maps.Map') 

    but to be fair, thats kinda silly way to initialize the map when it should work by calling..

    new Microsoft.Maps.Map(

    because thats how you do it with google maps:

    _map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

    So it has the exact same initialization as google maps but with some random extra step!?

    *edit* Also would like to mention that the sample code for windows store apps has not been updated to 8.1

    http://code.msdn.microsoft.com/Bing-Maps-SDK-for-Metro-31b378eb

    Wednesday, October 30, 2013 4:50 AM
  • The line Microsoft.Maps.loadModule('Microsoft.Maps.Map') doesn't initialize the map, it loads in the Bing Maps module/code base. This is done to ensure that no Bing Maps related code is run before the full Bing Maps code base is loaded. The web version of Bing Maps doesn't need to do this as the browser already prevents this from happening as it is generally not as asynchronous as Windows 8 when it comes to loading in JavaScript files.

    http://rbrundritt.wordpress.com

    Wednesday, October 30, 2013 8:57 AM
    Owner