capacitor-community / google-maps

Capacitor Plugin using native Google Maps SDK for Android and iOS.

Home Page:https://capacitor-community.github.io/google-maps/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat(myLocation): call MyLocationButton programmatically

DwieDima opened this issue · comments

!! This feature request is related to the fork of @tafelnl !!

Is your feature request related to a problem? Please describe.
Currently it is possible to display the native myLocationButton in the map, which allows navigation to the current location.
At the moment, programmatic navigation is not possible, which excludes two important use-cases:

  1. Navigation to the current location, due to life-cycle events or a specific business logic.
  2. Creating custom UI to trigger navigation to the current location (e.g. using ion-fab-button instead of MyLocationButton). This also allows the button to be placed anywhere (instead of just bottom right)

A workaround would be the method moveCamera() by querying the current location beforehand.
However, this loses the advantage of the event listener didTapMyLocationButton().

Describe the solution you'd like
Extend CapacitorGoogleMaps with the method tapMyLocationButton(), which triggers the click on myLocationButton.

commented

Thanks for opening this issue. I am not aware of such a feature in either the iOS or the Android SDK. We will divert from the
"standard" API significantly by implementing this . I think Google might have good reasons not to implement this into their SDKs. So I don't want to divert too much. But maybe I overlooked something in the docs and it actually does exist. If that's the case, could you please share the link?

Of course this use case is special since in the Android or iOS SDK, it would typically not happen that you'd have an overlay HTMLElement in place. But still it would be possible in Android and iOS to remove the default myLocationButton and replace it with your own as well. And even then you would still need to do the custom logic you described above as well.

What do you think?

I quickly did some research and also did not find such a method natively.
However, I found some similar feature requests for various frameworks like flutter.
According to this comment, MyLocationButton is natively created by the SDK and can't be edited either.
The correct approach here would actually also be a manual animation to the current location.

I found the implementation on stackoverflow, where for IOS and Android only a few lines of code are needed.
At this point, of course, the question arises whether this "workaround" is performed by the client, or by plugin.

In your documentation I have not yet found a method that allows retrieving the current location (correct me here if I'm wrong).

For me as a enduser of this plugin, implementing this to the plugin brings of course a lot of comfort.
If you choose not to add this to the plugin, a method for retrieving the current location must be provided.

Whats your opinion about that?
For me using getMyCurrentLocation() and moveCamera() clientside sounds like the correct way to keep this plugin standard.

commented

In your documentation I have not yet found a method that allows retrieving the current location (correct me here if I'm wrong).

Yeah that's the thing. Retrieving the location should be done by using the offical Capacitor geolocation plugin. It would not make sense to include such a method in this plugin. But since adding a feature like tapMyLocationButton actually requires adding such functionality, it is a bit contradictory.

Maybe I could add this functionality on the JavaScript side only, and then make @capacitor/geolocation a dependency for that specific method. So with a bundler, like webpack, you would still profit from correct treeshaking and not unnecessary adding @capacitor/geolocation when it's not needed. And you would also not have to write boilerplate code (since it is part of the JS side of this plugin).

However, this would require the Capacitor team (or anyone for that matter) to first answer my open question here: ionic-team/capacitor#5429

@tafelnl doing this experiment, all method execution from the web is handle by Capacitor to the plugin using the Two-Way communication system of the browser (postMessage). There's not actual parsing, everything is converted to a Dictionary. (Reference). In this point you can parse and get the element, but there's no easy way to overwrite this method.

Edit: This is from iOS perspective