admin管理员组

文章数量:1025502

Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that es up is:

SCRIPT5022: InvalidValueError: initMap is not a function js, line 102 character 390

the error refers to the call to google maps API, not in my js.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* e first in the head; any other head content must e *after* these tags -->
  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <!-- Bootstrap -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

  <!-- JS -->

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<script src='js/device.min.js'></script>
</head>
      <div class="col-md-6 col-sm-12 col-xs-12">
        <div class="container-fluid">
          <div id="map-canvas"></div>
        </div>
      </div>

<--some more code filler that nobody needs to see,-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src=".11.3/jquery.min.js"></script>
<!-- Include all piled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.ui.accordion.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src=";libraries=places&callback=initMap" async defer></script>
<script src="js/main.js"></script>

and my javascript:

function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}

Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that es up is:

SCRIPT5022: InvalidValueError: initMap is not a function js, line 102 character 390

the error refers to the call to google maps API, not in my js.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* e first in the head; any other head content must e *after* these tags -->
  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <!-- Bootstrap -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

  <!-- JS -->

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<script src='js/device.min.js'></script>
</head>
      <div class="col-md-6 col-sm-12 col-xs-12">
        <div class="container-fluid">
          <div id="map-canvas"></div>
        </div>
      </div>

<--some more code filler that nobody needs to see,-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all piled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.ui.accordion.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyDFmJX1o4ocAPluAPlDWlh-VX_35iwc23o&libraries=places&callback=initMap" async defer></script>
<script src="js/main.js"></script>

and my javascript:

function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}
Share Improve this question asked Apr 13, 2016 at 19:07 Jgoo83Jgoo83 3773 silver badges17 bronze badges 3
  • 1 Check for your browser version of IE.. developers.google./maps/documentation/javascript/… – Hussain Patel Commented Apr 13, 2016 at 19:11
  • Are you running a supported version of IE? – geocodezip Commented Apr 13, 2016 at 19:18
  • what warranted the downvote? – Jgoo83 Commented Apr 13, 2016 at 19:21
Add a ment  | 

2 Answers 2

Reset to default 5

So I moved my main.js file above the call to the googlemaps API and it fixed the problem. I am assuming that the the call was being made before all my javascript loaded, hence the callback to the mapsInit didn't exist yet. Would love some feedback if my thinking is correct/incorrect. Thanks

<script src="js/main.js"></script>
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyDFmJX1o4ocAPluAPlDWlh-VX_35iwc23o&libraries=places&callback=initMap" async defer></script>

I was getting the same error as above, but the marked answer didn't help. If anyone is getting the initMap error only on Internet explorer it could be because you are using JavaScript that is too modern for Internet Explorer including 'template literals' and 'arrow functions'. I went through my code and replaced them with older code which removed this error. Hopefully that will save someone the hours of debugging I went through...

Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that es up is:

SCRIPT5022: InvalidValueError: initMap is not a function js, line 102 character 390

the error refers to the call to google maps API, not in my js.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* e first in the head; any other head content must e *after* these tags -->
  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <!-- Bootstrap -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

  <!-- JS -->

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<script src='js/device.min.js'></script>
</head>
      <div class="col-md-6 col-sm-12 col-xs-12">
        <div class="container-fluid">
          <div id="map-canvas"></div>
        </div>
      </div>

<--some more code filler that nobody needs to see,-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src=".11.3/jquery.min.js"></script>
<!-- Include all piled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.ui.accordion.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src=";libraries=places&callback=initMap" async defer></script>
<script src="js/main.js"></script>

and my javascript:

function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}

Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that es up is:

SCRIPT5022: InvalidValueError: initMap is not a function js, line 102 character 390

the error refers to the call to google maps API, not in my js.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* e first in the head; any other head content must e *after* these tags -->
  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <!-- Bootstrap -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

  <!-- JS -->

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<script src='js/device.min.js'></script>
</head>
      <div class="col-md-6 col-sm-12 col-xs-12">
        <div class="container-fluid">
          <div id="map-canvas"></div>
        </div>
      </div>

<--some more code filler that nobody needs to see,-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all piled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.ui.accordion.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyDFmJX1o4ocAPluAPlDWlh-VX_35iwc23o&libraries=places&callback=initMap" async defer></script>
<script src="js/main.js"></script>

and my javascript:

function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}
Share Improve this question asked Apr 13, 2016 at 19:07 Jgoo83Jgoo83 3773 silver badges17 bronze badges 3
  • 1 Check for your browser version of IE.. developers.google./maps/documentation/javascript/… – Hussain Patel Commented Apr 13, 2016 at 19:11
  • Are you running a supported version of IE? – geocodezip Commented Apr 13, 2016 at 19:18
  • what warranted the downvote? – Jgoo83 Commented Apr 13, 2016 at 19:21
Add a ment  | 

2 Answers 2

Reset to default 5

So I moved my main.js file above the call to the googlemaps API and it fixed the problem. I am assuming that the the call was being made before all my javascript loaded, hence the callback to the mapsInit didn't exist yet. Would love some feedback if my thinking is correct/incorrect. Thanks

<script src="js/main.js"></script>
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyDFmJX1o4ocAPluAPlDWlh-VX_35iwc23o&libraries=places&callback=initMap" async defer></script>

I was getting the same error as above, but the marked answer didn't help. If anyone is getting the initMap error only on Internet explorer it could be because you are using JavaScript that is too modern for Internet Explorer including 'template literals' and 'arrow functions'. I went through my code and replaced them with older code which removed this error. Hopefully that will save someone the hours of debugging I went through...

本文标签: javascriptGoogle Maps in Internet ExplorerStack Overflow