user2604150 user2604150 - 1 year ago 212
AngularJS Question

Ionic Framework does not show Google Maps

I'm trying to learn Ionic Framework and I'm stuck on Google Maps part.
I have been simply trying to display a map on the screen but instead I see a white screen.
Any help will be appreciated!

Here is my index.html code:

<!DOCTYPE html>
<html ng-app="app">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">


<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/controllers.js"></script>
<script src="js/index.js"></script>
<script src="cordova.js"></script>
<script src=""></script>


<ion-nav-bar class="bar-positive">
<ion-nav-back-button class="button-icon ion-arrow-left-c">

And here is my index.js code:

angular.module('app', ['ionic', 'app.controllers'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
if(window.StatusBar) {

.config(function($stateProvider, $urlRouterProvider) {

.state('signin', {
url: '/sign-in',
templateUrl: 'templates/sign-in.html',
controller: 'SignInCtrl'

.state('menu', {
url: '/menu',
abstract: true,
templateUrl: 'templates/menu.html'
.state('menu.jukebox', {
url: '/jukebox',
views: {
'menuContent': {
templateUrl: 'templates/jukebox.html',
.state('venues', {
url: '/venues',
templateUrl: 'templates/venues.html',
controller: 'VenuesCtrl'
.state('venues.venueList', {
url: '/venueList',
'venueDetails': {
templateUrl: 'templates/venueList.html',
controller: 'VenueListCtrl'

.state('venues.venueMap', {
url: '/venueMap',
'venueDetails': {
templateUrl: 'templates/venueMap.html',
controller: 'venueMapCtrl'




angular.module('app.controllers', [])

.controller('SignInCtrl', function($scope, $state) {

$scope.signIn = function(user) {
console.log('Sign-In', user);


Authenticate user through Firebase, if authenticated, go to menu.jukebox state.

.controller('VenuesCtrl', function($scope){

$scope.hideBackButton = true;

.controller('VenueListCtrl', function($scope){

Dummy array for venues. It will be changed with the data from the server.

$scope.venues = [
{ id: 1, name: 'Lucky Strike San Fransisco', distance: '0.3 km', image: '' },
{ id: 2, name: 'Match', distance: '0.7 km', image: '' },
{ id: 3, name: 'Supercell', distance: '0.9 km', image: '' },
{ id: 4, name: 'The Melt', distance: '4 km', image: '' }

.controller('venueMapCtrl', function($scope, $ionicLoading) {
console.log('map', 'reached that far');

google.maps.event.addDomListener(window, 'load', function() {

var myLatlng = new google.maps.LatLng(37.3000, -120.4833);

var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP

var map = new google.maps.Map(document.getElementById("map"), mapOptions);

navigator.geolocation.getCurrentPosition(function(pos) {
map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
var myLocation = new google.maps.Marker({
position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
map: map,
title: "My Location"

$ = map;



<ion-view view-title="Venues" hide-back-button="true">
<div class="tabs-striped tabs-top tabs-background-positive tabs-color-light">
<div class="tabs">
<a class="tab-item active" ui-sref="venues.venueList">
<i class="icon ion-ios-list"></i>
<a class="tab-item" ui-sref="venues.venueMap">
<i class="icon ion-map"></i>
<ion-nav-view name="venueDetails"></ion-nav-view>


<ion-view view-title="VenueMap">
<div id="map" data-tap-disabled="true"></div>


<ion-view view-title="VenueList">
<ion-content style="padding-top: 50px;">
<div class="list">

<a ng-repeat="venue in venues"
class="item item-thumbnail-left">

<img ng-src="{{ venue.image }}">
<h2>{{ }}</h2>
<p>{{ venue.distance }}</p>



.scroll {
height: 100%;

#map {
width: 100%;
height: 100%;

Answer Source

I solved the problem with the help of this page. The problem was Ionic's code sample. Better use:

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download