Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps get Boundary Co-ordinates

I am using Google Maps v2 in my application. When the user pans or zooms on the screen I would like to get the area of the map based on which I want to fetch the POI only in the screen view part.
I went through the documentation but could not find any help.

like image 908
Harsha M V Avatar asked Feb 05 '13 05:02

Harsha M V


People also ask

How do I get city boundaries on Google Maps?

To see it yourself, go to Google Maps and search for a city name or even a zip code. You will see a pinkish highlight around the border. Based on your zoom level, as you zoom out, Google will highlight the whole area, not just the borders, in the pink color.

How do I see Geocodes on Google Maps?

Go to the Google Cloud Console. Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open. From the list of APIs on the Dashboard, look for Geocoding API. If you see the API in the list, you're all set.


2 Answers

You need to use Projection and VisibleRegion classes in order to get visible LatLng region.
So your code would look something like:

LatLngBounds curScreen = googleMap.getProjection()     .getVisibleRegion().latLngBounds; 
like image 174
Pavel Dudka Avatar answered Oct 10 '22 15:10

Pavel Dudka


In Android(Kotlin) you can find LatLng this way, in every time zoom or. gesture detect

private var mMap: GoogleMap? = null ..........        mMap?.setOnCameraMoveStartedListener { reasonCode ->         if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {             val curScreen: LatLngBounds =  mMap!!.getProjection().getVisibleRegion().latLngBounds             var northeast=curScreen.northeast             var southwest=curScreen.southwest             var center=curScreen.center             Log.v("northeast LatLng","-:"+northeast)             Log.v("southwest LatLng","-:"+southwest)             Log.v("center LatLng","-:"+center)         }     } 
like image 27
shirsh shukla Avatar answered Oct 10 '22 16:10

shirsh shukla