I am trying to implement Google maps in Angularjs using ui.Map ( http://angular-ui.imtqy.com/ui-map/ )
I carefully followed the example and loaded the map, I can create a marker in the center of the map, and the "map-tilesloaded" event works fine.
My problem is adding a marker that the user clicks on. The click function gets the empty parameter $ params. In my controller:
$scope.newMapOptions = { center : new google.maps.LatLng($scope.position.lat, $scope.position.lng), zoom : 18, mapTypeId : google.maps.MapTypeId.ROADMAP }; $scope.getLocation = function() { if (navigator.geolocation) { return navigator.geolocation.getCurrentPosition(setPosition); } }; $scope.addMarker = function($event, $params) { $scope.newTingMarker = new google.maps.Marker({ map : $scope.myNewTingMap, position : $params[0].latLng }); }; $scope.initMap = function() { if (!$scope.mapLoaded) $scope.getLocation(); $scope.mapLoaded = true; }; function setPosition(pos) { $scope.position = { lat : pos.coords.latitude, lng : pos.coords.longitude }; $scope.meMarker = new google.maps.Marker({ map : $scope.myNewTingMap, position : new google.maps.LatLng($scope.position.lat, $scope.position.lng) }); $scope.myNewTingMap.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); $scope.$apply(); }
html:
<div ui-map-info-window="myInfoWindow"> <b>Current location</b> </div> <div ui-map-marker="meMarker" ></div> <div ui-map-marker="newTingMarker" ui-event="{'map-click': 'openMarkerInfo(newTingMarker)'}"></div> <section id="newTingMap" > <div ui-map="myNewTingMap" ui-options="newMapOptions" class="map-canvas" ui-event="{'map-tilesloaded': 'initMap()', 'map-click': 'addMarker($event, $params)' }"></div> </section>
$ scope.addMarker should receive $ event and $ params, where $ params [0] has a latlng object. This is currently an empty array: []
I am using angular 1.1.5, but I tried using the same as the ui.Map example without effect.
I should also note that this is in the view, but its output outside the view in the main controller does not matter.
If I try to execute the code launched from the ui-map directive, I see that the latlng object starts in this case:
Ui-map.js:
angular.forEach(eventsStr.split(' '), function (eventName) {
element.triggerHandler ('map-' + eventName, event); ... has a latlng object in the 'event', but seems to be lost after that
angularjs google-maps-api-3 angular-ui
user2890027
source share