Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - how to get map coordinates from map view

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?

like image 834
suresh cheemalamudi Avatar asked Feb 04 '13 09:02

suresh cheemalamudi


People also ask

How do I extract coordinates from a map?

First, open Google Maps on your computer, right-click the place you want to get coordinates. A pop-up window will show, you can find the latitude and longitude on the top. Left-click and copy them automatically.

How can I get latitude and longitude from address in Android?

The short story is you need to do: Geocoder geocoder = new Geocoder(this, Locale. getDefault()); List<Address> addresses = geocoder. getFromLocation(lat, lng, 1);

How do I get latitude on my Android?

Steps to get current latitude and longitude in Android Location permissions for the manifest file for receiving the location update. Create LocationManager instance as a reference to the location service. Request location from LocationManager. Receive location update from LocationListener on change of location.


2 Answers

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.

like image 146
YannPl Avatar answered Sep 27 '22 18:09

YannPl


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());
}
like image 23
Corbella Avatar answered Sep 27 '22 19:09

Corbella