dimanche 29 avril 2018

Google Maps throws Unexpected Token error - mapTypeId when running JS.

Index.php file: I am using the script links on my index.php files to make sure it recognizes the Google API from the web. Unable to figure out why is it giving me that error. Any help would be very beneficial.

//Script is attached at the head of the HTML
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyArRvb1kURQjMQQGaFs9dN2dWvACvBGF3c">

//script is attached at the bottom of the page with all the other javascript files linked to the index.php    
<script src="map.js"></script>

<!--Google Map-->
<div id="googleMap"></div>

Map.js file: It keeps giving me a parsing error: Unexpected Token; mapTypeId: google.maps.mapTypeId.Roadmap;

var map;
//set map options
var myLatLng = {lat: 38.7628, lng: -93.7360};
var mapOptions= {
    center: myLatLng,
    zoom: 10,
    mapTypeId: google.maps.mapTypeId.ROADMAP;
}

//onload
google.maps.event.addDomListener(window, 'load', initialize);

//initialize: draw map in the #googleMap div
function initialize(){
    //create map
    map = new google.maps.Map(document.getElementById("googleMap"),mapOptions);     
}

Styling.css file: Styling coed used to make the map appear on the page.

#googleMap{
    width: 100%;
    height: 30vh;
    margin: 10px auto;
}




Aucun commentaire:

Enregistrer un commentaire