5

In my application I am displaying places using markers on google maps. But I am marking all the available places at once which I don't want to do. I wanted to display the places which only fits into the screen by fetching the maps coordinates as shown below:

enter image description here

I wanted only to fetch the places that are available in this range from the source by sending the coordinates of the maps. I am not sure whether I should capture all the 4-coordinates from the corners of the screen?

Can anyone help me to figure out this?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
suresh cheemalamudi
  • 6,190
  • 11
  • 49
  • 67

4 Answers4

4

You can get those by using this method:

    yourMapView.getMap().getCameraPosition();

This returns you a CameraPosition object. The coordinates of the camera is given by the field target and the zoom level by the field zoom. Now you should be able to calculate the aproximate coordinates of the screen corners.

YannPl
  • 1,312
  • 1
  • 14
  • 30
  • thanks Zarkaos. I am still confused with what to do? does this link have something to help me. http://stackoverflow.com/questions/10985487/android-opengl-es-2-0-screen-coordinates-to-world-coordinates – suresh cheemalamudi Feb 04 '13 at 09:56
  • 1
    I'm not an expert with using maps in Android :s But your link seems to be for a diffrent situation with OpenGl. I don't tink you can use it in your application.. – YannPl Feb 04 '13 at 10:02
  • ok. after obtaining camera position how can i resolve this into lat lon values? because i guess i should compare this lat lon value with the other places lat lon values in my database. – suresh cheemalamudi Feb 04 '13 at 10:06
  • As I said in my answer, you have the field target in the CameraPosition which gives you a LatLng object. Refer to [LatLng reference](http://developer.android.com/reference/com/google/android/gms/maps/model/LatLng.html) for getting lon and lat values from LatLng object. – YannPl Feb 04 '13 at 10:08
  • I tried with your solution. It is returning the lat lon values of the center of the screen – suresh cheemalamudi Feb 04 '13 at 10:43
1

To obtain the TopLeft and BottomRight coordinates of the map at any time, use the following:

public GeoPoint getCurrentTL(MapView map){
    Projection pr = map.getProjection();
    return pr.fromPixels(0, 0);
}

public GeoPoint getCurrentBR(MapView map){
    Projection pr = map.getProjection();
    return pr.fromPixels(map.getWidth(), map.getHeight());
}
Corbella
  • 1,791
  • 14
  • 24
1

So, this is an old question, but here's a fresh take on the issue.

You can ask for the visible region when the map is up (visible) with:

VisibleRegion vRegion = mMap.getProjection().getVisibleRegion();
LatLng upperLeft = vRegion.farLeft
LatLng lowerRight = vRegion.nearRight;
Eric Fossum
  • 2,395
  • 4
  • 26
  • 50
1

The other way, we can use LatLngBounds. It returns 2 points: northeast and southwest.

VisibleRegion vRegion = mMap.getProjection().getVisibleRegion();
LatLng southwest = vRegion.latLngBounds.southwest;
LatLng northeast = vRegion.latLngBounds.northeast;

https://developers.google.com/maps/documentation/android-api/views

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Chi Minh Trinh
  • 296
  • 4
  • 11