sebholstein/angular-google-maps

Is there a way to get mapWrapper instance so that I can play with geocoding/reverseGeocoding

parmod-arora opened this issue ยท 10 comments

Thanks for this wonderful repo and Is there a way to get mapWrapper instance so that I can play with geocoding/reverseGeocoding in my own components.

import {GoogleMapsAPIWrapper} from 'angular2-google-maps/services/google-maps-api-wrapper';

...

@component(...

providers: [GoogleMapsAPIWrapper]

...

constructor(private _mapsWrapper: GoogleMapsAPIWrapper){}

Simply injecting GoogleMapsAPIWrapper will not do the trick there, because _map is private (private _map: Promise<mapTypes.GoogleMap>) and not accessible in component

writing new google.maps.Geocoder() in component is also not working. due to google is undefined error.

So how can i get map instance from GoogleMapsAPIWrapper Service ??

@parmod-arora

I could introduce a new method getMap to get the google map instance from the wrapper. Then you could write a custom component like this (for quick workaround, that works with the current version, you could use the private _map Promise):

<sebm-google-map [latitude]="lat" [longitude]="lng">
  <my-comp></my-comp>
</sebm-google-map>
@Component({
  selector: 'my-comp'
})
export class MyComp {
  constructor(private _wrapper: GoogleMapsAPIWrapper) {
    this._wrapper.getMap().then((m) => {
      // implement your own logic
    }
  }
}

sounds like a good idea =]

@SebastianM

I created a pull request. #155 (feat(SebmGoogleMap): exposing _map Instance from GoogleMapsAPIWrapper)

but build is failing and i am not able to figure out why ?

https://travis-ci.org/SebastianM/angular2-google-maps/builds/111165799

Can you look at the pull request and provide some kind of documentation for sending pull-requests.

@parmod-arora thanks for the PR. There was an issue in Travis CI. Can you do a rebase (shorten the commit message and add only on commit to the PR)? Then the build should be green.
Thanks!

Oh BTW: I will also add some contribution guidelines very soon.

Thanks for your suggestions,

Every things works as expected please merge below PR.

#161

Hi I put together a working example of accessing the native map, it seems to be a little confusing how to use it at first.

https://github.com/philipbrack/example-angular2-google-maps-getNativeMap

@SebastianM @philipbrack is the code you provided still working? GoogleMapsAPIWrapper doesn't seem to have a getMap() method, and neither does the getNativeMap() method actually returns a native map.