question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Maps: ReferenceError: google is not defined.

See original GitHub issue

How i can solve my problem with google maps, i’ve inserted the google api link in index.html and after run the app i’ve got an error.

My code snippets:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

declare var google: any;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {

  }

  ionViewDidLoad() {
      let mapEle = document.getElementById('map');

      let map = new google.maps.Map(mapEle, {
        center: '-34.9290, 138.6010',
        zoom: 16
      });

      let infoWindow = new google.maps.InfoWindow({
        content: `<h5>IONIC</h5>`
      });

      let marker = new google.maps.Marker({
        position: '-34.9290, 138.6010',
        map: map,
        title: 'title'
      });

      marker.addListener('click', () => {
        infoWindow.open(map, marker);
      });

      google.maps.event.addListenerOnce(map, 'idle', () => {
        mapEle.classList.add('show-map');
      });
  }

}

NB: Knowing that I followed a method in this example (conference app).

My system information:

Cordova CLI: 5.4.1
Gulp version:  CLI version 3.9.0
Gulp local:  
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.1
Ionic App Lib Version: 2.1.1
Ionic App Scripts Version: 0.0.36
ios-deploy version: 1.8.6 
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v5.12.0
Xcode version: Xcode 8.0 Build version 8A218a 

screen shot 2016-10-20 at 9 29 07 pm

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

12reactions
mahmoudissmailcommented, Nov 1, 2016

Problem Solved.

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

declare var google: any;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {
    platform.ready().then(() => {
      this.loadMap();
    });
  }
loadMap() {
      let mapEle = document.getElementById('map');
      let map = new google.maps.Map(mapEle, {
        center: new google.maps.LatLng(43.071584, -89.380120),
        zoom: 16
      });

      let infoWindow = new google.maps.InfoWindow({
        content: `<div class="marker_maps"><h2>Title</h2></div>`
      });

      var image = {
        url: 'assets/img/marker.png', // image is 256 x 256
        scaledSize : new google.maps.Size(60, 60),
      };

      let marker = new google.maps.Marker({
        position: new google.maps.LatLng(43.071584, -89.380120),
        map: map,
        icon: image,
        title: 'Title'
      });

      marker.addListener('click', () => {
        infoWindow.open(map, marker);
      });

    google.maps.event.addListenerOnce(map, 'idle', () => {
      mapEle.classList.add('show-map');
    });
  }
}

Note: @inceptiveDipak

Replace

  • Center Attribute ('-34.9290, 138.6010') with (new google.maps.LatLng(43.071584, -89.380120))
  • Position marker attribute ('-34.9290, 138.6010') with (new google.maps.LatLng(43.071584, -89.380120))
  • Remove all the code from ionViewDidLoad and call directly in
platform.ready().then(() => { 
 this.loadMap();
});

And should it work perfectly 😄 .

1reaction
yuukiiicommented, Jan 14, 2018

Also make sure you have :

<script src=“http://maps.google.com/maps/api/js?key=YOUR_API_KEY_HERE”></script>

<script src="cordova.js"></script>`

in your src/index.html file - above cordova.js

YOUR_API_KEY_HERE can be had from here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Maps API throws "Uncaught ReferenceError
google is not defined, google related stuff has not been loaded yet and we are using it that causes this error. In the...
Read more >
Uncaught ReferenceError: google is not defined - MSDN
Usually this type of error is due to forgetting to reference a JavaScript library or trying to access a library object before the...
Read more >
Google Maps API v3 - Uncaught ReferenceError - OutSystems
I'm trying to create a Google Map in a webscreen but I keep getting this error in Chrome's Javascript Console : "Uncaught ReferenceError:...
Read more >
google is not defined - ionic v3.9.2, angular v5.2.11
Hello guys, i know this error is pretty common but i still have no idea which part did i do wrong. i already...
Read more >
Google Maps API throws Uncaught ReferenceError ... - Edureka
When I try to load the page using AJAX, I get the error: Uncaught ReferenceError: google is not defined. This is the page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found