Android Google Maps get Boundary Co-ordinates

20,386

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)
        }
    }
Share:
20,386

Related videos on Youtube

Harsha M V
Author by

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, 2021

Comments

  • Harsha M V
    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
    Harsha M V about 11 years
    i tried this i am getting only northwest and southwest value. any idea how to get the other two values ?
  • Pavel Dudka
    Pavel Dudka about 11 years
    northeast 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
    Harsha M V about 11 years
    how 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
    Pavel Dudka about 11 years
    well, 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 as Y axis and longitude as X axis
  • Pavel Dudka
    Pavel Dudka about 11 years
    as 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
    stackunderflow about 9 years
    @HarshaMV your question seem doesn't signifies your reputations
  • Harsha M V
    Harsha M V about 9 years
    @Dagon see the date it was asked ;-)
  • stackunderflow
    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
    kgandroid almost 9 years
    It is returning 0.0 both latitude and longitude,any idea??
  • Pavel Dudka
    Pavel Dudka almost 9 years
    @kgandroid usually it means that current location is not known at the moment
  • kgandroid
    kgandroid almost 9 years