# Google Maps integration

**URL:** <https://forum.ionicframework.com/t/google-maps-integration/157>\
**Category:** ionic-v1\
**Created:** [December 6, 2013, 5:06am UTC](https://forum.ionicframework.com/t/google-maps-integration/157 "2013-12-06T05:06:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajbraus](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ajbraus/32/63991_2.png) [@ajbraus](https://forum.ionicframework.com/u/ajbraus)\
**Post date:** [December 6, 2013, 5:06am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/1 "2013-12-06T05:06:59Z")

</div>

I am trying to add a basic google maps script to add a googlemap on a #map-canvas div. I’ve tried adding the below code to the controller on tab.load, just before the #map-canvas div in a and in a separate map.js file. I am already loading the google maps api js script and there are no errors.

```
var madison = new google.maps.LatLng(43.073052, -89.401230);
var minneapolis = new google.maps.LatLng(44.983334, -93.266670);

var map;
function initialize() {
  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(43.073052, -89.401230),
    scrollwheel: false
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  directionsService = new google.maps.DirectionsService();
  directionsDisplay = new google.maps.DirectionsRenderer({
    suppressMarkers: false,
    suppressInfoWindows: true
  });
  directionsDisplay.setMap(map);

  var request = {
    origin: madison, 
    destination: minneapolis,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });

  directionsDisplay1 = new google.maps.DirectionsRenderer({
    suppressMarkers: false,
    suppressInfoWindows: true
  });
  directionsDisplay1.setMap(map);
  
}
google.maps.event.addDomListener(window, 'load', initialize);

```

---

<div class="post-metadata">

**Author:** ![ajbraus](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ajbraus/32/63991_2.png) [@ajbraus](https://forum.ionicframework.com/u/ajbraus)\
**Post date:** [December 6, 2013, 5:27am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/2 "2013-12-06T05:27:03Z")

</div>

Maybe things would be cleaner if I used

> **[moshen/node-googlemaps](https://github.com/moshen/node-googlemaps)**
>
> A simple way to query the Google Maps API from Node.js - moshen/node-googlemaps

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/max/32/137761_2.png) [@max](https://forum.ionicframework.com/u/max)\
**Post date:** [December 11, 2013, 2:01am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/3 "2013-12-11T02:01:33Z")

</div>

@ajbraus, what happens when you run this? Did you take a look at the map example in the repo: [https://github.com/driftyco/ionic/tree/master/examples/starters/map](https://github.com/driftyco/ionic/tree/master/examples/starters/map)

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forum.ionicframework.com/u/gaurav)\
**Post date:** [February 1, 2014, 1:18pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/4 "2014-02-01T13:18:25Z")

</div>

Hello @max,

I have successfully implemented the starter map example with some more enhancements (actually have added markers of locations which come from server as json).  
But the problem Now I am facing is when I tried the same examples by putting this `<div id="map">` in a new html file for rendering it in `<ng-view></ng-view>`. It did not initialize the map.  
This part did not initialize `google.maps.event.addDomListener(window, 'load', initialize);` the `initialize()` function in `MapCtrl`.

What’s the best way to go ? I already saw angular-google-maps but did not like it as why to add so many scripts.

Thanks  
Gaurav

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forum.ionicframework.com/u/gaurav)\
**Post date:** [February 2, 2014, 11:55am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/5 "2014-02-02T11:55:10Z")

</div>

Hello @max,

I have successfully implemented it in using `<ng-view></ng-view>`. But the problem in my case, seems to be very strange.  
I did not have anchor tag in my deisgn `<a ng-click="centerOnMe()" class="button button-icon icon ion-navigate">Find Me</a>`, that is why map is not loading. I tested it by adding that tag and everything works fine. Also, When I removed this tag in the experiment using I created, there also it did not worked.

So, Now I am solved with this problem, now next problem I have now is that when I go to next view and come back on map view, map did not load up now.

I will make a plunker to show what I am saying, if you did not get it. Sorry if I am did not read any concept of angular or ionic.

Thanks  
Gaurav

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forum.ionicframework.com/u/gaurav)\
**Post date:** [February 3, 2014, 8:19am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/6 "2014-02-03T08:19:59Z")

</div>

Hello @max,

Implementing Google Maps using `<ng-view></ng-view>` worked when tested on my desktop browser, but its not working in Android.

Do Anyone have tested Google Maps in ng-view without using angular-google-map directive ?

Thanks  
Gaurav

---

<div class="post-metadata">

**Author:** ![guyz](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@guyz](https://forum.ionicframework.com/u/guyz)\
**Post date:** [February 25, 2014, 6:26pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/7 "2014-02-25T18:26:03Z")

</div>

How did you end up solving the problem of the initialize function not being executed? (domlistener not being hit). I can’t even get my map to initialize due to the function never being called when i hit my view.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forum.ionicframework.com/u/gaurav)\
**Post date:** [February 28, 2014, 9:36am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/8 "2014-02-28T09:36:43Z")

</div>

Hello @guyz,

At Last I implemented the angular-google map directive. This is a custom directive [www.angular-google-maps.org](http://www.angular-google-maps.org) you can use that it works perfectly fine.

Thanks  
Gaurav

---

<div class="post-metadata">

**Author:** ![antoniogiungato](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@antoniogiungato](https://forum.ionicframework.com/u/antoniogiungato)\
**Post date:** [March 18, 2014, 4:57pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/9 "2014-03-18T16:57:21Z")

</div>

Hey @gaurav, I’m trying to use [www.angular-google-maps.org](http://www.angular-google-maps.org) and everything is working… but I can’t drag the map around!  
I already put “draggable: true” inside the options.  
Did you hit this problem too?

---

<div class="post-metadata">

**Author:** ![Robin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robin/32/64162_2.png) [@Robin](https://forum.ionicframework.com/u/Robin)\
**Post date:** [March 18, 2014, 6:26pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/10 "2014-03-18T18:26:44Z")

</div>

I strongly recommend using `LeafletJS` and `angular-leaflet-directive` in combination with the Google Maps plugin. It’s awesome, powerful and very easy to use.

The app I’m building at this moment utilizes LeafletJS with support for offline maps (tiles downloaded from OpenStreetMaps or Google Maps Street HD).

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forum.ionicframework.com/u/gaurav)\
**Post date:** [March 19, 2014, 4:07pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/11 "2014-03-19T16:07:53Z")

</div>

Hello @antoniogiungato,  
Please try using like this `<google-map draggable='true'></google-map>` inside the google-map. I think you are trying it setting in javascript file. I am not sure about that, as I used it like this given on api page [http://angular-google-maps.org/api](http://angular-google-maps.org/api)

---

<div class="post-metadata">

**Author:** ![darrenahunter](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@darrenahunter](https://forum.ionicframework.com/u/darrenahunter)\
**Post date:** [March 20, 2014, 1:26am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/12 "2014-03-20T01:26:45Z")

</div>

hey robin

I am currently using google maps - and all is well with it. However am interested to try Leaflet as have heard only good things about it.  
Do you have a codepen or example you could share to get us up and running

cheers  
Darren

---

<div class="post-metadata">

**Author:** ![doronsever](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@doronsever](https://forum.ionicframework.com/u/doronsever)\
**Post date:** [March 20, 2014, 8:08am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/13 "2014-03-20T08:08:53Z")

</div>

Have u tried using Geolocation service to set the coords of the user instead of hardcoded ones?  
I cannot get this to work. Even not with service injected.

---

<div class="post-metadata">

**Author:** ![doronsever](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@doronsever](https://forum.ionicframework.com/u/doronsever)\
**Post date:** [March 20, 2014, 11:09am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/14 "2014-03-20T11:09:53Z")

</div>

Hey,  
I’ve managed to get this to work, but i can’t set the center to be the user’s location via the geolocation service.

Have u manage to get this to work?

---

<div class="post-metadata">

**Author:** ![Robin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robin/32/64162_2.png) [@Robin](https://forum.ionicframework.com/u/Robin)\
**Post date:** [March 20, 2014, 1:06pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/15 "2014-03-20T13:06:02Z")

</div>

@darrenahunter: [http://lmgtfy.com?q=angular+leaflet+directive](http://lmgtfy.com?q=angular+leaflet+directive)

Just kidding 😉 The Angular Leaflet Directive demo website has some great examples.

Website: [http://tombatossals.github.io/angular-leaflet-directive/#!/](http://tombatossals.github.io/angular-leaflet-directive/#!/)

And for the code junkies: [http://jsfiddle.net/tombatossals/4PhzC/](http://jsfiddle.net/tombatossals/4PhzC/)

---

<div class="post-metadata">

**Author:** ![darrenahunter](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@darrenahunter](https://forum.ionicframework.com/u/darrenahunter)\
**Post date:** [March 20, 2014, 9:11pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/16 "2014-03-20T21:11:50Z")

</div>

Thanks Robin - ha hadn’t seen lmgtfy before but will use it myself now

leaflet does look interesting - will give it a go - like idea it can be offline

update: just had a go with the fiddle and put in my coords - very very slow to load the tiles - tried a few other coords and equally slow. is this usual?

sticking with gmaps

cheers

---

<div class="post-metadata">

**Author:** ![Robin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robin/32/64162_2.png) [@Robin](https://forum.ionicframework.com/u/Robin)\
**Post date:** [March 21, 2014, 12:34am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/17 "2014-03-21T00:34:50Z")

</div>

Mine is insanely fast. Depends on your tile service I guess. I’m downloading Google Maps HD tiles using Mobile Atlas Creator and store the tiles offline in my app. This does increase the app size dramatically so be careful with offline maps.

---

<div class="post-metadata">

**Author:** ![antoniogiungato](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@antoniogiungato](https://forum.ionicframework.com/u/antoniogiungato)\
**Post date:** [March 23, 2014, 8:30pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/18 "2014-03-23T20:30:01Z")

</div>

@Robin Is that legal?

I have a somewhat related question, please forgive me for not posting in a new thread.  
If I put a google map in a view inside a navigation stack, let’s say in the pet-detail view of the seed project, this line (taken from the codepen map example):

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

```

is never called until I refresh the page in the browser.  
I think it’s pretty trivial, but can you point me in the right direction?

---

<div class="post-metadata">

**Author:** ![Robin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robin/32/64162_2.png) [@Robin](https://forum.ionicframework.com/u/Robin)\
**Post date:** [March 24, 2014, 1:14pm UTC](https://forum.ionicframework.com/t/google-maps-integration/157/19 "2014-03-24T13:14:58Z")

</div>

@antoniogiungato About the legal stuff; still need to figure that out. I suspect with the correct copyright notices etc. this won’t be any problem.  
It’s not like I’m pretenting it’s **my** data. I will show the Google logo on it and give them the credits in the about page.

Does anyone else have some insights on this subject?

---

<div class="post-metadata">

**Author:** ![catatonicrelaps](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catatonicrelaps/32/7538_2.png) [@catatonicrelaps](https://forum.ionicframework.com/u/catatonicrelaps)\
**Post date:** [April 24, 2014, 2:32am UTC](https://forum.ionicframework.com/t/google-maps-integration/157/20 "2014-04-24T02:32:56Z")

</div>

> [@Robin](#):
>
> @antoniogiungato About the legal stuff; still need to figure that out. I suspect with the correct copyright notices etc. this won’t be any problem.

Just a cursory look at the Leaflet FAQ

> I want to use Google Maps API tiles with Leaflet, can I do that?

> The problem with Google is that its Terms of Use forbid any means of tile access other than through the Google Maps API.

And from our dear friends at the GooglePlex…

> 1. License Restrictions. Except as expressly permitted under the Terms, or unless you have received prior written authorization from Google (or, as applicable, from the provider of particular Content), Google’s licenses above are subject to your adherence to all of the restrictions below.

> 10.1 Restrictions on How You May Use the Maps API(s). Except as explicitly permitted in Section 8 (Licenses from Google to You) or the Maps APIs Documentation, you must not (nor may you permit anyone else to) do any of the following:

> 10.1.1. General Restrictions.  
> (a) No Access to Maps API(s) except through the Service. You must not access or use the Maps API(s) or any Content through any technology or means other than those provided in the Service, or through other explicitly authorized means Google may designate. For example, you must not access map tiles or imagery through interfaces or channels (including undocumented Google interfaces) other than the Maps API(s).

Come on now, if you could store the tiles offline everyone would be using that strategy. That’s the Enterprise class subscription/tiers are for.

[Next page](https://forum.ionicframework.com/t/google-maps-integration/157.md?page=2)
