capacitor-community / google-maps

Capacitor Plugin using native Google Maps SDK for Android and iOS.
https://capacitor-community.github.io/google-maps/
MIT License
152 stars 64 forks source link

Info window not showing #181

Closed eeschiavo closed 2 years ago

eeschiavo commented 2 years ago

Describe the bug The Info Window not appearing when tapping on marker.

To Reproduce Create a list of markers like:

this.newMap.addMarkers(branches.map((branch: BankBranchModel) => {
      const marker = {
        title: branch.title,
        snippet: branch.description,
        coordinate: {
          lat: branch.lat,
          lng: branch.lng
        },
        isFlat: true
      } as Marker;
     console.log('Marker: ', marker);
      return marker;
    }))

This will output:

{
    "title": "Branch title example",
    "snippet": "Branch description example",
    "coordinate": {
        "lat": 41.9,
        "lng": 12.4
    },
    "isFlat": true
}

Expected behavior Tapping on marker nothing happen. Info Window should appear showing title and snippet.

Screenshots Example

Additional context Full code map init:

ionViewDidEnter() {
    this.createMap()
      .pipe(
        switchMap(() => this.service.getBranches(this.coordinates.lat, this.coordinates.lng)),
        tap((branches) => this.branches = branches),
        switchMap((branches: BranchModel[]) => this.addBranchMarkers(branches)),
        tap(() => this.addClickListenerOnMarker()),
        last()
      )
      .subscribe({ complete: () => this.spinnerService.hide() });
  }
createMap(): Observable<any> {
    return from(GoogleMap.create({
      id: 'id-map',
      element: this.mapRef.nativeElement,
      apiKey: environment.googleApiKey,
      config: {
        center: {
          lat: this.coordinates.lat,
          lng: this.coordinates.lng,
        },
        zoom: 10
      }
    }))
      .pipe(
        map((googleMap) => this.newMap = googleMap),
        switchMap(() => from(this.newMap.enableCurrentLocation(true)))
      );
  }
addBranchMarkers(branches: BranchModel[]) {
    return from(this.newMap.addMarkers(branches.map((branch: BranchModel) => {
      const marker = {
        title: branch.title,
        snippet: branch.description,
        coordinate: {
          lat: branch.lat,
          lng: branch.lng
        },
        isFlat: true
      } as Marker;
      console.log('Marker: ', marker);
      return marker;
    })));
  }

addClickListenerOnMarker() {
    this.newMap.setOnMarkerClickListener((marker: Marker) => {
      this.log.debug('Marker click:', marker);
    });
  }

The app is Angular based.

tafelnl commented 2 years ago

Which version of the plugin are you using? You seem to be using methods that do not exist (at least not in the current version). setOnMarkerClickListener does not exist. You are probably looking for this method instead.

Also the following piece of code:

GoogleMap.create({
      id: 'id-map',
      element: this.mapRef.nativeElement,
      apiKey: environment.googleApiKey,
      config: {
        center: {
          lat: this.coordinates.lat,
          lng: this.coordinates.lng,
        },
        zoom: 10
      }
    })

is not according to the API reference in the documentation.

Please make sure you are reading the documentation and following all the steps.

eeschiavo commented 2 years ago

I was completely wrong, I actually confused the @capacitor/google-maps plugin with @capacitor-community/google-maps. I apologize.