1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54// install :
// link :
// Google Maps needs ALOT of work!
// Not for production use
angular.module('ngCordova.plugins.googleMap', [])
.factory('$cordovaGoogleMap', ['$q', '$window', function ($q, $window) {
var map = null;
return {
getMap: function (options) {
var q = $q.defer();
if (!$window.plugin.google.maps) {
q.reject(null);
} else {
var div = document.getElementById('map_canvas');
map = $window.plugin.google.maps.Map.getMap(options);
map.setDiv(div);
q.resolve(map);
}
return q.promise;
},
isMapLoaded: function () { // check if an instance of the map exists
return !!map;
},
addMarker: function (markerOptions) { // add a marker to the map with given markerOptions
var q = $q.defer();
map.addMarker(markerOptions, function (marker) {
q.resolve(marker);
});
return q.promise;
},
getMapTypeIds: function () {
return $window.plugin.google.maps.mapTypeId;
},
setVisible: function (isVisible) {
var q = $q.defer();
map.setVisible(isVisible);
return q.promise;
},
// I don't know how to deallocate te map and the google map plugin.
cleanup: function () {
map = null;
// delete map;
}
};
}]);