allenhwkim / angularjs-google-maps

The Simplest AngularJS Google Maps V3 Directive
http://ngmap.github.io
MIT License
1.52k stars 516 forks source link

Not able to switch language dynamically #876

Open adeelasghar88 opened 5 years ago

adeelasghar88 commented 5 years ago

I am using ngmap version 1.18.4, angular version 1.4.9. I want to switch language but it didn't reflect. I saw couple of issues that are already discussed, e.g. https://github.com/allenhwkim/angularjs-google-maps/issues/760

Above issue closed by suggesting to remove script tag. I don't have script tag which loads google-maps.

index.html: <script src='bower_components/ngmap/build/scripts/ng-map.js'></script>

Controller code:

$scope.markers = [$scope.latitude, $scope.longitude];
$scope.mapParams = 'language=' + $scope.locale;    

$timeout(function() {
  NgMap.getMap({id: 'site-map'}).then(function(map) {
    google.maps.event.trigger(map, 'resize');
    map.setCenter(new google.maps.LatLng($scope.latitude, $scope.longitude));
  });
}, 2000);

Html code:

 <div map-lazy-load="https://maps.google.com/maps/api/js?key=abc&v=3.34" map-lazy-load-params="{{ mapParams }}">
    <ng-map id="site-map" center="{{[ latitude, longitude ]}}" zoom="question.zoom"
    >
      <marker position="{{ markers }}"></marker>
    </ng-map>
 </div>

I tried different combinations in map-lazy-load-params but nothing worked. Few combinations were: $scope.mapParams = '&language=' + $scope.locale; $scope.mapParams = 'https://maps.googleapis.com/maps/api/js&language=' + $scope.locale;

Static language works perfectly fine like I did this to verify map language change or not. <div map-lazy-load="https://maps.google.com/maps/api/js?key=abc&v=3.34&language=ja">

Can someone tell me the solution?