I\'ve been trying to set up click event listeners on the google.maps.Map
object that\'s created by the ui-gmap-google-map
directive from the Angula
By my testing and by what I've read in the docs and in various issue comments, it seems that this (waiting for the control
object to get augmented) is one of the things that the uiGmapIsReady
service in Angular Google Maps was designed for.
My current understanding is that uiGmapGoogleMapApi
should be used to wait for async loading of the Google Maps API and uiGmapIsReady
should be used to wait for uiGmap*
directives and all they entail (including control
object augmentation) to complete. The naming says it all.
Here's a new demo fiddle. This demo's usage of IsReady
:
IsReady.promise().then(function (maps) {
var map1 = $scope.control.getGMap();
var map2 = maps[0].map;
alert(map1 === map2); // true
});
IsReady.promise
(source) accepts an optional integer argument indicating (I'm pretty sure) the number of ui-gmap-google-map
directives your page is using. It defaults to 1
. (If you happen to give it a "wrong" number, I believe there's a (remote?) possibility that the returned promise will never resolve.)
I ended up using vanilla JS and got everything to work with no headache. Angular Google Maps is a cool idea, but at least in my case, the issues outnumber the benefits.
After spending an hour or so on github and stackoverflow, I realised that the proposed solutions (like https://github.com/angular-ui/angular-google-maps/issues/308) were a hack of a hack, and since my task was just "display some markers on a map and center the map on them" I don't want to use a hack.
The gmaps documentation contains tons of examples (in vanilla JS) that can be used in an Angular app, copy + paste and you're done.
Again, this is my personal experience, might not be the same for you