The issue is likely that you are trying to use the Microsoft.Maps namespace before the map control script is loaded. The V8 map script loads asynchronously for performance, however this means that if you try to access namespace in code right after the script tag to load the map control, the namespace won't be there. You need your code to wait until the map script is loaded. You can handle this by adding a callback function name to the map script tag URL. For example:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript'>
var map;
function GetMap()
{
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'YourBingMapsKey'
});
//Add your post map load code here.
}
</script>
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
</head>
<body>
<div id="myMap" style=";width:800px;height:600px;"></div>
</body>
</html>
We also recommend adding the map script tag after your map load code. The reason for this is that if the page is refreshed, the map script will be cached and will call the callback function right away, so the callback function needs to already be loaded.