Marco Chillemi's personal page pensieri e parole su web

20nov/110

Secondo appuntamento Gtub Milano

Il 24 novembre, alle 19.30, in centro a Milano (vicino piazzale Lodi) si terrà il secondo incontro del Gtub Milano.
Si parlerà dello sviluppo di Android, NFC e per chi volesse si potrà proseguire la serata in un pub bavarese.

Tutte le info qui:

http://www.googlab.it/2011/11/gtug-secondo-incontro-del-gtug-milano.html

Condividi...

8mar/110

Android Mapview: getLatitudeSpan and getLongitudeSpan don’t work

Hi there,
during last days I had to handle some problems using  methods getLatitudeSpan and getLongitudeSpan of a MapView in my MapActivity.

My MapActivity is a child activity of a tabbed main Activity, and I needed to obtain width and height (in terms of latitude and longitude) of the current map showed.

MapView gives us two methods to retrive these informations:

  • getLatitudeSpan(); gives us back the latitude span in decimal degrees * 1,000,000
  • getLongitudeSpan(); gives us back the longitude span in in decimal degrees * 1,000,000

(Remember that, perhaps for performance reason, we'll use MapView with the integer rappresentation of the double value, obtained multiplying by one million the latitude and longitude)

But.... there is a problem.

If you run a code like the following:

public class tabmap extends MapActivity{
MapView mappa;
MapController mc;
@Override
protected void onCreate(Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.tabmap);
mappa = (MapView) findViewById(R.id.mapview);
mc = mappa.getController();
GeoPoint point = new GeoPoint(45464198, 9191493);
mc.setCenter(point);
Integer latitudeSpan = mappa.getLatitudeSpan();
Integer longitudeSpan = mappa.getLongitudeSpan();
//What are the values for latitudeSpan and longitudeSpan??
}}

Basically you'll see the value 0 for latitudeSpan and 36000000 for longitudeSpan (wrong values!!!). This is, I suppose, beacause MapView object needs some time to "realize" about itself and to setup. Maybe is has to exchange some datas with Google service.
So, how can I get the score?
I found a way, I don't know if it's the best practice you can use, but i resolved the matter. Go no after the break if you want to read about it.

Condividi...