Pedro,
I've been working on roughly the same thing today... see the thread
MapView.getLatitudeSpan..
All you're running into is that the map isn't ready when you are asking
for the getLatitudeSpan, so you need to wait until it is ready...OR...
the formula I've come up with to calculate it is this :
Note that I don't expect this formula is perfect.. and I can certainly
make it more compact and faster by reworking it, but for working on it I
wanted to do it step by step :).
private class LatLonSpans
{
@SuppressWarnings("unused")
public double LatSpan = 0.0;
@SuppressWarnings("unused")
public double LonSpan = 0.0;
}
private LatLonSpans getSpans()
{
LatLonSpans latLonSpans = new LatLonSpans();
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int zoomLevel = mapView.getZoomLevel();
// zoomToPower times 256 should be equal to the pixels required
to view the entire world
// at the resolution I've set.
double zoomToPower = Math.pow(2, zoomLevel - 1);
// it takes 256 pixels to view the entire world at resolution
1, so this should be the pixels required to view the entire world
// at the resolution I've set.
double entireWorld = zoomToPower * 256;
// Now I need to scale the zoomToPower to my screen size to figure
// out what I'm really going to see.
//
// this is how many pixels to see 1 degree.
double OneDegree = entireWorld / 360;
// and for height we have x pixels minus 40???? to account for
top bars..... so we will see this much of a degree.
double heightSpan = (height - 40) / OneDegree;
double widthSpan = width / OneDegree;
latLonSpans.LatSpan = heightSpan;
latLonSpans.LonSpan = widthSpan;
return latLonSpans;
}
and I'm using it like this :
if (mapView.getLatitudeSpan() == 0)
{
nvps.add(new BasicNameValuePair("latitudespan",
String.valueOf(latLonSpans.LatSpan)));
}
else
{
nvps.add(new BasicNameValuePair("latitudespan",
String.valueOf(latSpan / 1E6)));
}
Hope it helps... and if anyone can poke holes in my formula .. PLEASE
DO... I'd love to know it doesn't work BEFORE I start relying on it. :).
On 25/06/2010 5:55 PM, Pedro Teixeira wrote:
New approach that makes more sense:
int latSpan = mapView.getLatitudeSpan();
int longSpan = mapView.getLongitudeSpan();
GeoPoint mapCenter = mapView.getMapCenter();
int topLatitude = mapCenter.getLatitudeE6() + (latSpan/2);
int bottomLatitude = mapCenter.getLatitudeE6() - (latSpan/2);
int leftLongitude = mapCenter.getLongitudeE6() - (latSpan/2);
int rightLongitude = mapCenter.getLongitudeE6() + (latSpan/2);
But this values:
int latSpan = mapView.getLatitudeSpan();
int longSpan = mapView.getLongitudeSpan();
are giving me 36000000 and 0 :/
On Jun 25, 2010, at 9:15 PM, Frank Weiss wrote:
Exactly. You need to pass the neLatitude, neLongitude, swLatitude,
swLongitude as query parameters to your back end web service, which
then returns only POIs whose latitude and longitude fall within those
bounds, like this Javascript Google Map does:
http://myhome.bankofamerica.com/?findmlo=94114#/findmlo/94105
Notice that it even handles panning and zooming.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Pedro Teixeira
www.pedroteixeira.org <http://www.pedroteixeira.org>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Sincerely,
Brad Gies
-----------------------------------------------------------------------
Bistro Bot - Bistro Blurb
http://www.bgies.com
http://www.bistroblurb.com
http://www.ihottonight.com
-----------------------------------------------------------------------
Never doubt that a small group of thoughtful, committed people can
change the world. Indeed. It is the only thing that ever has - Margaret Mead
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en