gpt4 book ai didi

Android:从像素坐标获取纬度/经度

转载 作者:行者123 更新时间:2023-11-29 01:27:36 26 4
gpt4 key购买 nike

我目前正在开发一个在 map 上“模拟”鼠标(带指针)的 Android 应用程序。我已经实现了 pad,它能够将指针(一个简单的小 View )移动到 map 层上。现在我需要创建 addMarker 功能。我有的是:

  • (x,y) 指针坐标(以像素为单位)(或倾角);
  • 宽度和高度映射属性。

我的问题是:如何计算指针接触点的纬度/经度?非常感谢!

最佳答案

你可以这样做:

Projection myProjection = myMap.getProjection()

获取 map 的投影:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#getProjection()

Returns a Projection object that you can use to convert between screen coordinates and latitude/longitude coordinates.

The Projection returned is a snapshot of the current projection, and will not automatically update when the camera moves. As this operation is expensive, you should get the projection only once per screen. Google Maps uses the Mercator projection to create its maps from geographic data and convert points on the map into geographic coordinates.

然后:

LatLng markerPosition = myProjection.fromScreenLocation(pointerPosition);

https://developers.google.com/android/reference/com/google/android/gms/maps/Projection.html#fromScreenLocation(android.graphics.Point)

Returns the geographic location that corresponds to a screen location. The screen location is specified in screen pixels (not display pixels) relative to the top left of the map (not the top left of the whole screen).

Parameters: point A Point on the screen in screen pixels.

Returns: The LatLng corresponding to the point on the screen, or null if the ray through the given screen point does not intersect the ground plane (this might be the case if the map is heavily tilted).

关于Android:从像素坐标获取纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33066381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com