Android Google Maps get Boundary Co-ordinates
Solution 1
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;
Solution 2
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)
}
}
Related videos on Youtube
Harsha M V
I turn ideas into companies. Specifically, I like to solve big problems that can positively impact millions of people through software. I am currently focusing all of my time on my company, Skreem, where we are disrupting the ways marketers can leverage micro-influencers to tell the Brand’s stories to their audience. People do not buy goods and services. They buy relations, stories, and magic. Introducing technology with the power of human voice to maximize your brand communication. Follow me on Twitter: @harshamv You can contact me at -- harsha [at] skreem [dot] io
Updated on January 29, 2021Comments
-
Harsha M V about 3 years
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. -
Harsha M V about 11 yearsi tried this i am getting only northwest and southwest value. any idea how to get the other two values ?
-
Pavel Dudka about 11 yearsnortheast and southwest you mean? If so - that's how the bounding box is represented (top-right and bottom-left corners of the viewport). Given these two points it is pretty straight forward to calculate other 2 points. Right? The simplest way to check whether certain POI(LatLng) is within the box - is to call
LatLngBounds.contains(LatLng point)
interface. However, displaying big amount of Markers on a map is a separate story -
Harsha M V about 11 yearshow can i get get the other two points, am sorry am confused. Ant about showin a lot of markers is there any optimized way of doing that ?
-
Pavel Dudka about 11 yearswell, top-left corner would have
[curScreen.southwest.longitude;curScreen.northeast.latitude]
coordinates and bottom-right corner would have[curScreen.northeast.longitude;curScreen.southwest.latitude]
coordinates. You can treat latitude asY
axis and longitude asX
axis -
Pavel Dudka about 11 yearsas far as I know, there is no native way to clusterize markers on a map. There is a good article though about this topic: developers.google.com/maps/articles/toomanymarkers
-
stackunderflow about 9 years@HarshaMV your question seem doesn't signifies your reputations
-
Harsha M V about 9 years@Dagon see the date it was asked ;-)
-
stackunderflow about 9 years@HarshaMV i see. that was toooo long ago. is that the day when you're still at primary school? actually i refer to your question comment. anyway thank you for your post and also for the answer. it solved my today's problem
-
kgandroid almost 9 yearsIt is returning 0.0 both latitude and longitude,any idea??
-
Pavel Dudka almost 9 years@kgandroid usually it means that current location is not known at the moment
-
kgandroid almost 9 yearsPlase have a look: stackoverflow.com/questions/31446401/latlng-bound-returns-0-0