Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Listeners on Android not firing? #86

Closed
J-Gonzalez opened this issue Jun 24, 2021 · 5 comments
Closed

Event Listeners on Android not firing? #86

J-Gonzalez opened this issue Jun 24, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@J-Gonzalez
Copy link

Describe the bug
On android, it seems any event listener (outside of map ready) is not firing. Same app on IOS is working fine.

To Reproduce
Have created various event listeners

CapacitorGoogleMaps.addListener("didTapAt", () => {
        console.log("map tapped!");
      });

CapacitorGoogleMaps.addListener("didChange", () => {
        console.log("map changed!");
      });

Expected behavior
didChange, didTap, didTapAt to trigger event listener. Is this working for others?

@J-Gonzalez J-Gonzalez added the bug Something isn't working label Jun 24, 2021
@tafelnl
Copy link
Member

tafelnl commented Jun 24, 2021

Event listeners have different names on Android. This is a bit unfortunate but it will be normalized in v2!

For now the following events are sent out on Android:

  • didTapPOIWithPlaceID (click on POI)
  • didTapAt (click on map)
  • didTap (click on marker)
  • onMyLocationClick (click on (blue) my-location dot)

@J-Gonzalez
Copy link
Author

Interesting. I seem to not be getting the didTapAt event to fire at all. Does Android have some logic on where I should be adding the listeners? Should it be inside onMapReady listener (in JS code) or should it not matter?

As a side note, I was able to get 'didChange' to fire by putting cameraIdle inside of onMapReady, but don't think this is the correct approach at all (my Java and native code writing is VERY rusty)

    @Override
    public void onMapReady(GoogleMap googleMap) {
        this.googleMap = googleMap;
        notifyListeners("onMapReady", null);

        this.googleMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
            @Override
            public void onCameraIdle() {
                notifyListeners("didChange", null);
            }
        });
    }

@tafelnl
Copy link
Member

tafelnl commented Jun 28, 2021

@J-Gonzalez That is a pretty valid approach. It could be refactored of course. But it does its job well.

I am not part of the maintenance team, but I am working hard to get a v2 release out there: #85

@svrakata
Copy link

For everyone wondering. For events to fire call
await CapacitorGoogleMaps.setOnMarkerClickListener();
await CapacitorGoogleMaps.setOnMapClickListener();
in the onMapReady handler.

@tafelnl
Copy link
Member

tafelnl commented Mar 16, 2022

We've just released a (pretty stable) beta for version 2 of this plugin under the name @capacitor-community/google-maps.

It features a more complete and consistent API. Also the map can finally be rendered behind the webview in this new version.

Extensive documentation for v2 can be found here: https://capacitor-community.github.io/google-maps/

Since version 1 lacked a lot of (basic) features, did not have good coding practices, had a poor API and it is not recommended to use it anymore, we've dropped support for it. Therefore I will close this issue. We believe version 2 offers a better Developer Experience and is a much better fit for anyones use case.

@tafelnl tafelnl closed this as completed Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants