0

I am trying to implement a google map in my ionic app.

I am able to dynamically generate markers, but can't seem to bind infowindows.

$scope.arrayOfMarkers = [];
for (var i = 0 ; i < results.length ; i++) {
    var user = results[i];
    var mySID = JSON.parse(window.localStorage.getItem("userObject")).userProfileId;
    if (user.userProfileId != mySID) {
        var userCoords = {
            latitude: user.userProfileLatitude,
            longitude: user.userProfileLongitude
        };
    var markerOptions = {
        animation: "drop"
    }
    var thisMarker = {
        id:i,
        coords: userCoords,
        options: markerOptions,
        idKey: i,
        window: {
            show: false,
            title: "Test"
        }
}
$scope.arrayOfMarkers.push(thisMarker);
   }
}

HTML

<ui-gmap-google-map id="map" center="map.center" zoom="map.zoom">
                <ui-gmap-marker ng-repeat="marker in arrayOfMarkers" coords="marker.coords" options="marker.options"  events="marker.events" idkey="marker.id" window="marker.window">                
                </ui-gmap-marker>
            </ui-gmap-google-map>

When I click the markers nothing happens. How should I be implementing window?

http://angular-ui.github.io/angular-google-maps/#!/

2
  • you are not bind arrayOfMarkers to the scope $scope $scope.arrayOfMarkers = arrayOfMarkers; Commented Mar 12, 2016 at 14:26
  • I looked at the documentation I wonder where from you use window directive Commented Mar 12, 2016 at 14:36

2 Answers 2

1

You should put ui-gmap-window directive inside the ui-gmap-marker and call a function on click of marker. in my example call function toggleInfoWindow() like click="toggleInfoWindow()". it may help you

<ui-gmap-google-map id="map" center="map.center" zoom="map.zoom">
     <ui-gmap-marker ng-repeat="marker in arrayOfMarkers" coords="marker.coords" options="marker.options" click="toggleInfoWindow()" events="marker.events" idkey="marker.id" window="marker.window">  
           <ui-gmap-window options="windowOptions">
                <div>{{title}}</div> //your information here
            </ui-gmap-window>              
     </ui-gmap-marker>
 </ui-gmap-google-map>

In controller add toggleInfoWindow function:

$scope.toggleInfoWindow= function() {
     $scope.windowOptions.visible = !$scope.windowOptions.visible;
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so so much you have saved my sanity!
1

I looked at documentation did not found window directive but look what you can use

 <ui-gmap-windows show="{{window.show }}">
            <div ng-non-bindable>{{window.title}}</div>
 </ui-gmap-windows>

inside ui-gmap-marker to display window

you can refer to link doc for window

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.