ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

Google maps plugin not working for browser #289

Closed KMuthusamyms closed 4 years ago

KMuthusamyms commented 4 years ago

My code : **import { GoogleMaps, GoogleMap, GoogleMapsEvent, Marker, Environment } from '@ionic-native/google-maps'; loadMap() { this.platform.ready().then(() => {

  Environment.setEnv({

    // api key for server
    'API_KEY_FOR_BROWSER_RELEASE': '(MyKey)',
    // api key for local develoment
    'API_KEY_FOR_BROWSER_DEBUG': '(MyKey)'

  });
this.map = GoogleMaps.create('map_canvas', {});
this.delay(500).then(any=>{
  this.goToMyLocation();
});

}); }**

In the browser console shows error as follows:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'environment' of null TypeError: Cannot read property 'environment' of null at Function.push../node_modules/@ionic-native/google-maps/ngx/index.js.Environment.setEnv (index.js:610) at MapPage.push../src/app/map/map.page.ts.MapPage.loadMap (map.page.ts:41) at MapPage.push../src/app/map/map.page.ts.MapPage.ngOnInit (map.page.ts:38) at checkAndUpdateDirectiveInline (core.js:22099) at checkAndUpdateNodeInline (core.js:23363) at checkAndUpdateNode (core.js:23325) at debugCheckAndUpdateNode (core.js:23959) at debugCheckDirectivesFn (core.js:23919) at Object.eval [as updateDirectives] (MapPage_Host.ngfactory.js? [sm]:1) at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911) at resolvePromise (zone.js:831) at resolvePromise (zone.js:788) at zone.js:892 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423) at Object.onInvokeTask (core.js:17290) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195) at drainMicroTaskQueue (zone.js:601) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502) at invokeTask (zone.js:1744)

But it works fine in mobile devices. while comes to browser it shows error.

wf9a5m75 commented 4 years ago

Run the code after platform.ready().

KMuthusamyms commented 4 years ago

@wf9a5m75 I have added platform.ready() but it didn't work. still got the error.

ghost commented 3 years ago

I ran into this and had the following warning as well before the error:

common.js:297 Native: tried accessing the GoogleMaps plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

wf9a5m75 commented 3 years ago

Please try the hello world tutorial first. https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/hello-world/README.md

ghost commented 3 years ago

It should work fine within a block checking for platform.is('cordova').

wf9a5m75 commented 3 years ago

If you have an idea, please send a pull request