angular-google-maps: GoogleMapsAPIWrapper getBounds not returning

Hello, I am trying to get the maps bounds thourgh the GoogleMapsAPIWrapper service. I am using the Promise<LatLngBounds> function getBounds().

Nothing is returned.

Here’s my code.

constructor(private searchService: SearchService, 
    private wrapper: GoogleMapsAPIWrapper, 
    private _loader: MapsAPILoader, 
    private zone: NgZone) {
  }

  ngOnInit() {
   this.wrapper.getBounds().then(x => console.log(x));  
  }

the console.log function is not called as the peomise never returns anything.

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 21 (1 by maintainers)

Most upvoted comments

@SebastianM Im using Angular4, I can confirm GoogleMapsAPIWrapper’s promises don’t work.

Using sebm-google-map component inside a template you can use:

<sebm-google-map (boundsChange)="boundsChange($event)"></sebm-google-map>

and then inside your component:

boundsChange(event) {
    console.log(event.getNorthEast().lat());
    console.log(event.getNorthEast().lng());
    console.log(event.getSouthWest().lat());
    console.log(event.getSouthWest().lng());
  }

thanks to @jplew in this way can get Bounds 😉

latNorth: number
  @ViewChild(AgmMap) mapElement: any
  ...

  checkBounds(map) {

    const ln = this.mapElement._mapsWrapper.getBounds()
      .then( (latLngBounds) => {
        return latLngBounds.getNorthEast().lat()
      })
    ln.then( x => this.latNorth = x )

Even calling “getNativeMap” and doing “then” on that isn’t getting called at all.

I experienced the same issue when trying to do it on a component that had <sebm-google-maps> in the template. My workaround was to create a custom component to drop inside <sebm-googe-maps><custom-component></custom-component></sebm-google-maps> to perform the needed functionality.