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

feat(myLocation): call MyLocationButton programmatically #136

Open
DwieDima opened this issue Feb 16, 2022 · 4 comments
Open

feat(myLocation): call MyLocationButton programmatically #136

DwieDima opened this issue Feb 16, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@DwieDima
Copy link

DwieDima commented Feb 16, 2022

!! 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.

@DwieDima DwieDima added the enhancement New feature or request label Feb 16, 2022
@tafelnl
Copy link
Member

tafelnl commented Feb 16, 2022

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?

@DwieDima
Copy link
Author

DwieDima commented Feb 16, 2022

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.

@tafelnl
Copy link
Member

tafelnl commented Feb 18, 2022

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

@va2ron1
Copy link
Contributor

va2ron1 commented Feb 22, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants