从屏幕位置获取地理位置

kel*_*cer 2 android google-maps geolocation

我正在开发一个使用谷歌地图的应用程序.我可以在屏幕上获取特定点的地理位置吗?例如,我有一个在屏幕上有X和Y位置的视图(按钮,图像等).我想知道的是该位置的地理位置(纬度和经度)(视图位置).当然,这个位置(X和Y)在地图上.

kel*_*cer 5

我找到了解决方案.这是如何:

Projection projection = googleMap.getProjection();

// Returns the geographic location that corresponds to a screen location
LatLng geographicalPosition = projection.fromScreenLocation(new Point(your_X, your_Y)); 

// Returns a screen location that corresponds to a geographical coordinate 
Point screenPosition = projection.toScreenLocation(new LatLng(your_latitude, your_longitude));
Run Code Online (Sandbox Code Playgroud)

更多信息在这里.