how to get the long & lat value of four corners in the mapview in android?
Asked Answered
C

3

9

i working on map view. i want to put overlay item on the map view. that overlay items are all depends on currently showing map view and zoom level. how to get current map view's longitude and latitude of that four corner and how to analyze how many overlay item inside it. also we have to check thee zoom level.Any Idea? how to do it?

Caiman answered 19/3, 2010 at 10:6 Comment(0)
A
11

I think you have to use

mapview.getProjection().frompixel(intx, int y)

For the 4 corners of your screen (you can get their coordinates by getwidth and getheight on your mapView, and starting with (0,0), (getwidth(),0), (0,getheight()) and (getwidth(), getheight())

This will give you 4 geopoints from which you can extract latitude and longitude

Alonsoalonzo answered 19/3, 2010 at 10:33 Comment(1)
You're welcome, actually I had no idea of the answer of the answer when I saw your question but it triggered my interest and I looked for itAlonsoalonzo
C
7

If you're using the google-play-services library and the SupportMapFragment in particular.

this.getMap() will give you the instance of GoogleMap (which wraps MapView)

Then just:

map.getProjection().getVisibleRegion();

Castello answered 7/2, 2013 at 22:30 Comment(0)
K
6

Are you looking for something like this?

Projection proj = mapView.getProjection();
GeoPoint topLeft = proj.fromPixels(0, 0);

GeoPoint bottomRight = proj.fromPixels(mapView.getWidth()-1, mapView.getHeight()-1);

double topLat = topLeft.getLatitudeE6()/1E6;
double topLon = topLeft.getLongitudeE6()/1E6;
double bottomLat = bottomRight.getLatitudeE6()/1E6;
double bottomLon = bottomRight.getLongitudeE6()/1E6;

Hope it helps!

Kwashiorkor answered 5/4, 2011 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.