I'm getting the following error trying to use the geocoder service for the ng-map library:
angular.js:13642 ReferenceError: google is not defined
at Object.t [as geocode] (http://localhost:6240/Scripts/ng-map.min.js:25:28246)
I'm injecting the service into my controller
appModule.controller('MyController', ['$scope', 'NgMap', 'NavigatorGeolocation', 'GeoCoder',
function ($scope, NgMap, NavigatorGeolocation, GeoCoder) {
GeoCoder.geocode({address: 'Avenida Calle 26 # 40-40, Bogotá'}).then(function (result) {
//... do something with result
console.log('RESULT GEOCODER: ', result);
});
}]);
I also tested it with NgMap function getting the same reference error
NgMap.getGeoLocation('Avenida Calle 26 # 40-40, Bogotá').then(function (result) {
console.log('GETGEOLOCATION: ', result);
}, function (error) {
console.log('Error getting geolocation: ', error);
});
As shown in the snippet, I have successfully used other NgMap and NavigatorGeolocation services.
Here is the code of my page
<div map-lazy-load="https://maps.google.com/maps/api/js" map-lazy-load-params="{{ $ctrl.googleMapsUrl }}">
<div class="row">
<div class="col-md-6">
<ng-map id="map"
center="{{ $ctrl.mapCenter }}"
street-view="{{ $ctrl.svp }}"></ng-map>
</div>
<div class="col-md-6">
<ng-map id="sv" />
</div>
</div>
</div>
And in the corresponding controller/component
$ctrl.googleMapsUrl = "https://maps.googleapis.com/maps/api/js?key=MY-API-KEY";
$ctrl.mapCenter = 'current-location';
NavigatorGeolocation.getCurrentPosition({ timeout: 10000 }).then(function (ll) {
$ctrl.svp = "StreetViewPanorama(document.querySelector('ng-map#sv'), {position:new google.maps.LatLng(" + ll.coords.latitude + " , " + ll.coords.longitude + ")})";
}, function (error) {
console.log('error getCurrentPosition: ', error);
});
I'm using AngularJS v1.5.6
Thanks in advance for your help.