sebholstein / angular-google-maps

Angular 2+ Google Maps Components
https://angular-maps.com/
MIT License
2.03k stars 815 forks source link

Map setCenter from Page #303

Closed fdr2 closed 8 years ago

fdr2 commented 8 years ago

I was easily able to get the plugin working with my ionic2 app and found it much easier and cleaner than working on the lazy loading myself. I'm just having some issues figuring out how to get access to the Injectables provided.

After Importing directives and providers

import {
  ANGULAR2_GOOGLE_MAPS_PROVIDERS,
  ANGULAR2_GOOGLE_MAPS_DIRECTIVES
} from 'angular2-google-maps/core';

And passing them as arguments to Page

  providers: [[ANGULAR2_GOOGLE_MAPS_PROVIDERS]],
  directives: [[ANGULAR2_GOOGLE_MAPS_DIRECTIVES]],

I'm unable to figure out how to access the GoogleMapsAPIWrapper in order to setCenter(), for example. Can you provide any direction on how this is possible? I'm thinking I would need to instantiate the Injectable in my constructor and assign it to a member of this for use in other class methods, but I'm not sure how...

PS: I know this is more of an Angular2 question than an Angular2-Google-Maps question and appreciate any direction you can send me. Thanks!

esnare commented 8 years ago

Hey @ofanged1,

I am having the same issue. Every time that I add a new marker on my map it doesn't automatically get centered.

I also added this in my ts files:

import {GoogleMapsAPIWrapper} from'angular2-google-maps/services/google-maps-api-wrapper'; @Component(... providers: [GoogleMapsAPIWrapper] ...

//But when I do this, nothing happens constructor(private _wrapper: GoogleMapsAPIWrapper) { this._wrapper.getMap().then((m) => { console.log(m) }) }

fdr2 commented 8 years ago

Thanks @esnaremaussa, I think I'm going to move towards using a component to interact with the map as you have pointed out (and I should have realized from the angular2 quickstart).