locked
Uncaught ReferenceError: google is not defined RRS feed

  • Question

  • User1892050643 posted

    Hello guys

    Please help me for solving that problem

    I have code :

    var marker;
    var map;
    var mapProp;
    var myCenter;

    myCenter = new google.maps.LatLng(0.5719899, 124.3117468);
    mapProp = { center: myCenter, zoom: 15, scrollwheel: false, draggable: true, mapTypeId: google.maps.MapTypeId.HYBRID };
    map = new google.maps.Map(document.getElementById("LiveTrackingMap"), mapProp);
    marker = new google.maps.Marker({ });

    that code successfully working, but when I press ctrl + shift + i then goto console tab i got this error :

    Uncaught ReferenceError: google is not defined
    at HTMLDocument.<anonymous> ((index):338)
    at j (jquery-2.1.4.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.1.4.min.js:2)
    at Function.ready (jquery-2.1.4.min.js:2)
    at HTMLDocument.I (jquery-2.1.4.min.js:2)

    i enter to ((index):338) and appear my code is error :

    myCenter = new google.maps.LatLng(0.5719899, 124.3117468);.

    So, what should i do for fix that ??

    Regards

    Friday, August 30, 2019 7:57 AM

Answers

  • User61956409 posted

    Hi Indra JRN,

    Uncaught ReferenceError: google is not defined

    Please check if you have added the reference to required Google Maps JavaScript Library, like below. And please use browser f12 Network tool to check if the required JavaScript Libraries are loaded.

    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
      type="text/javascript"></script>

    Besides, please refer to the following documentation to quickly start exploring and developing applications with the Maps JavaScript API. 

    https://developers.google.com/maps/documentation/javascript/tutorial

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2019 3:28 AM

All replies

  • User475983607 posted

    Usually this type of error is due to forgetting to reference a JavaScript library or trying to access a library object before the library has been loaded in the browser.

    So, what should i do for fix that ??

    I recommend going through the Google code samples and tutorials.  

    Friday, August 30, 2019 1:28 PM
  • User61956409 posted

    Hi Indra JRN,

    Uncaught ReferenceError: google is not defined

    Please check if you have added the reference to required Google Maps JavaScript Library, like below. And please use browser f12 Network tool to check if the required JavaScript Libraries are loaded.

    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
      type="text/javascript"></script>

    Besides, please refer to the following documentation to quickly start exploring and developing applications with the Maps JavaScript API. 

    https://developers.google.com/maps/documentation/javascript/tutorial

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2019 3:28 AM