简体   繁体   中英

How to get currently displayed location on map

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 eg 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:)

To get camera position you can use:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM