cordova-plugin-googlemaps: Cannot read property 'getDiv' of undefined
hi , i have a problem in ionic 4
core.js:14597 ERROR TypeError: Cannot read property 'getDiv' of undefined at CordovaGoogleMaps._remove (js_CordovaGoogleMaps-for-browser.js:178) at Map.callback (BaseClass.js:115) at Map.trigger (BaseClass.js:70) at Map.remove (Map.js:670) at index.js:1124 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:16147) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:496)
package.json
"dependencies": {
"@angular/common": "~7.1.4",
"@angular/core": "~7.1.4",
"@angular/forms": "~7.1.4",
"@angular/http": "~7.1.4",
"@angular/platform-browser": "~7.1.4",
"@angular/platform-browser-dynamic": "~7.1.4",
"@angular/router": "~7.1.4",
"@ionic-native/camera": "^5.0.0-beta.22",
"@ionic-native/core": "^5.0.0-beta.22",
"@ionic-native/diagnostic": "^5.0.0-beta.22",
"@ionic-native/google-maps": "^5.0.0-beta.25",
"@ionic-native/image-picker": "^5.0.0-beta.22",
"@ionic-native/in-app-browser": "^5.0.0-beta.22",
"@ionic-native/native-storage": "^5.0.0-beta.22",
"@ionic-native/social-sharing": "^5.0.0-beta.22",
"@ionic-native/splash-screen": "5.0.0-beta.21",
"@ionic-native/status-bar": "5.0.0-beta.21",
"@ionic/angular": "4.0.0-rc.0",
"@ionic/pro": "2.0.4",
"cordova-browser": "5.0.4",
"cordova-plugin-camera": "^4.0.3",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-googlemaps": "^2.4.6",
"cordova-plugin-inappbrowser": "^3.0.0",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.3.1",
"cordova-plugin-nativestorage": "^2.3.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-telerik-imagepicker": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-plugin-x-socialsharing": "^5.4.3",
"cordova.plugins.diagnostic": "^4.0.10",
"core-js": "^2.5.4",
"es6-promise-plugin": "^4.2.2",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
html :
<ion-content>
<div id="map_canvas"></div>
</ion-content>
ts file :
async ngOnInit() {
await this.platform.ready();
await this.loadMap();
}
loadMap() {
const options: GoogleMapOptions = {
controls: {
compass: true,
myLocation: true,
myLocationButton: true,
zoom: true,
mapToolbar: true
}
};
this.map = GoogleMaps.create( 'map_canvas', options);
if (this.pos.latitude && this.pos.latitude !== 'null') {
const markerOption: MarkerOptions = {
icon: {
url: 'assets/img/marker.png',
size: {
width: 150,
height: 100
}
},
position: {lat: this.pos.latitude, lng: this.pos.longitude},
};
this.map.addMarkerSync(markerOption);
this.map.moveCamera({
target: {lat: markerOption.position.lat, lng: markerOption.position.lng},
zoom: 17
}).then(() => {
});
} else {
const opt: GeocoderRequest = {
address: this.pos.area.city.name + ' ' + this.pos.area.name
};
Geocoder.geocode(opt)
.then((results: GeocoderResult[]) => {
const circle: Circle = this.map.addCircleSync({
'center': results[0].position,
'radius': 500,
'strokeColor': '#17bbc1',
'strokeWidth': 2,
'strokeOpacity': 0.8,
'fillOpacity': 0.35,
'fillColor': '#17bbc1'
});
this.map.moveCamera({
target: circle.getBounds(),
zoom: 17,
}).then(() => {
});
});
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 30 (9 by maintainers)
I was able to resolve the issue. I am forgetting the exact details, but it had to do with the plugins I had not being the correct version. I updated all of the plugins to the appropriate beta and it worked.
Unfortunately for others, this is a project that I am hoping to monetize so I cannot share any of the working source code with you.
Btw mine worked after I tried to reinstall plugins.
And the code is
oh lol! very silly bug actually.
Set the dev css width and height and it will work …
#mapcanvas { width: 100%; height: 500px; }this is the problem :