angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

GoogleMapsAPIWrapper getBounds not returning

Open davideappiano opened this issue 10 years ago • 21 comments

Hello, I am trying to get the maps bounds thourgh the GoogleMapsAPIWrapper service. I am using the Promise 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

davideappiano avatar Oct 08 '16 12:10 davideappiano

@betfun where did you place this component inside your template? inside the component?

sebholstein avatar Nov 14 '16 20:11 sebholstein

I did this myself and it doesn't work either, this was on Component.

Uniphix avatar Nov 21 '16 06:11 Uniphix

Even calling "getNativeMap" and doing "then" on that isn't getting called at all.

Uniphix avatar Nov 21 '16 06:11 Uniphix

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.

ryan-morris avatar Jan 21 '17 19:01 ryan-morris

I have a similar issue. When I try to do the following: this._wrapper.getNativeMap().then((map) => console.log("mappp", map));

mappp is not printed out. How can I make sure, that the instance is the same like sebm-google-map instance?

I would appreciate any help

hesyar avatar Mar 16 '17 15:03 hesyar

I have a MapComponent which displays a map and I want to get its bounds from another component. How can I go about doing this?

mrsauravsahu avatar Mar 22 '17 13:03 mrsauravsahu

I'm also seeing the same issue as well.

halben avatar Apr 10 '17 16:04 halben

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());
  }

josueadelima avatar May 29 '17 03:05 josueadelima

@josueadelima Thanks! This only worked when the user pans over the map. I also need to get the bounds when the map is loaded and the user hasn't touched it.

craftpip avatar Jun 01 '17 06:06 craftpip

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

craftpip avatar Jun 01 '17 06:06 craftpip

@craftpip I'm getting the boundsChange event on map load too ...

josueadelima avatar Jun 01 '17 07:06 josueadelima

And as @craftpip mention promises are not working, also Angular4

Maybe (haven't test it) they work if you create the map using the GoogleMapsAPIWrapper and not the sebm-google-map template but then you loose a lot of the functionality that sebm-google-map gives you.

josueadelima avatar Jun 01 '17 07:06 josueadelima

I am trying to getBounds from the directive <agm-circle> on load. I tried to access the native element but I couldn't get AgmCircle object from the native element.

this.circleManager.getBounds(this.searchCircle).then((bounds) => { console.log(bounds); }); 

http://plnkr.co/edit/nG6lUsm1KLbQRv3SRdgW?p=preview

Appreciate any help on this.

pravinkumars avatar Jun 07 '17 12:06 pravinkumars

Any fix for this? I'm having the same problem and using the event is not really a solution.

cdarken avatar Sep 23 '17 22:09 cdarken

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 )

hesama110 avatar Oct 16 '17 10:10 hesama110

Promises still not work in Angular 4, but this is not only getBounds function, also another functions like createMarker where the promise doesn't get excuted

fabio0296 avatar Nov 15 '17 21:11 fabio0296

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 13 '18 22:11 stale[bot]

still having the same issue.

momentmuse avatar Nov 16 '18 18:11 momentmuse

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 14 '19 19:02 stale[bot]

Even now, still having the same issue, did someone get it to work?

Eraledm avatar Nov 29 '19 19:11 Eraledm