如何获取地图上当前显示的位置

huangapple go评论81阅读模式
英文:

How to get currently displayed location on map

问题

我正在制作一个基于地图SDK的Android应用程序。

我正在保存多个标记的位置,并希望在地图上显示它们。为了使数据库更快速且更轻量,我决定使用GeoFire仅显示靠近“特定位置”的标记。(如果全球范围内有数百万个标记,我不想全部显示出来,只显示在视图区域内的标记)

我希望那个“特定位置”是地图上当前显示区域的中心,这样当我将地图移动到不同的位置时,它会更新显示该区域内的标记。

我想要实现的目标类似于Google地图如何在您当前在地图上显示的区域中显示例如餐厅,并在您将地图移动到不同位置时实时更新。

问题是我没有看到任何简单的选项来检索地图上当前显示区域的位置。

我考虑过在屏幕中央创建一个不可见的标记,它会随地图移动,但对于这么简单的事情,这似乎是很多工作。

有没有更简单的方法可以实现这一点?

长话短说:我想获取当前屏幕上的位置。而不是手机的物理位置。

提前感谢您的帮助 如何获取地图上当前显示的位置

英文:

I'm making an Android app that's based around Maps SDK.

I'm saving locations of multiple markers and want to display them on the map. To make it faster and more lightweight for the Db I've decided to use GeoFire to display only markers that are close to a 'certain location'. (If there are milion markers around the world I don't want to display all of them. Just the ones that are in the viewing area)

I want that 'certain location' to be the middle of the currently displaying area on the map, so that when I move the map to a different location It'll update with markers that are in that area.

What I want to achieve is similar to how Google Maps displays e.g restaurants in an area you're currently displaying on your map and updates real time when you move the map to a different location.

Problem is I don't see any simple option to retrieve the location of a currently displaying area on the map.

I was thinking about creating an invisible marker in the middle of the screen that would move with the map but it seems like a lot of work for such a simple thing.

Is there any easier way I can achieve this?

So long story short: I want to get the location that's currently on the screen. Not the physical location of the phone.

Thanks in advance 如何获取地图上当前显示的位置

答案1

得分: 1

获取相机位置的方法如下:

double mylat = mGoogleMap.getCameraPosition().target.latitude;
double mylon = mGoogleMap.getCameraPosition().target.longitude;
英文:

To get camera position you can use:

> double mylat = mGoogleMap.getCameraPosition().target.latitude;
> double mylon = mGoogleMap.getCameraPosition().target.longitude;

huangapple
  • 本文由 发表于 2020年7月25日 19:00:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63087514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定