[go: nahoru, domu]

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

Map width for current zoom #122

Open
Dzivo opened this issue May 18, 2022 · 3 comments
Open

Map width for current zoom #122

Dzivo opened this issue May 18, 2022 · 3 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@Dzivo
Copy link
Dzivo commented May 18, 2022

How can we get map width for current zoom level. For example to stretch GroundOverlay over whole map view.

@Dzivo Dzivo added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 18, 2022
@barbeau
Copy link
Contributor
barbeau commented May 20, 2022

@Dzivo You should be able to use the CameraPositionState.projection and the android-maps-ktx library sphericalDistance() function to get the width of the screen in meters.

Something like this:

val upperLeftLatLng = cameraPositionState.projection.fromScreenLocation(Point(0, 0))
val upperRightLatLng = cameraPositionState.projection.fromScreenLocation(Point(0, size.width.toInt()))
val canvasWidthMeters = upperLeftLatLng.sphericalDistance(upperRightLatLng)

This is how I implemented the draft version of the ScaleBar in googlemaps/android-maps-ktx#175, which is sized to a percentage of the width of the screen.

Could you give that a shot and let me know if it works?

@barbeau barbeau added type: question Request for information or clarification. Not an issue. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. triage me I really want to be triaged. labels May 20, 2022
@barbeau
Copy link
Contributor
barbeau commented Jun 24, 2022

Here's what I ended up using in the ScaleBar port to maps-compose (see PR #157) to account for the cameraPositionState.projection being nullable:

val upperLeftLatLng =
	cameraPositionState.projection?.fromScreenLocation(Point(0, 0))
		?: LatLng(0.0, 0.0)
val upperRightLatLng =
	cameraPositionState.projection?.fromScreenLocation(Point(0, size.width.toInt()))
		?: LatLng(0.0, 0.0)
val canvasWidthMeters = upperLeftLatLng.sphericalDistance(upperRightLatLng)

@stale
Copy link
stale bot commented Jun 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

@stale stale bot added the stale label Jun 18, 2023
@kikoso kikoso added the priority: p3 Desirable enhancement or fix. May not be included in next release. label Jul 10, 2023
@stale stale bot removed the stale label Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants