my location on multiple activities

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

my location on multiple activities

Postby spagi » Wed May 05, 2010 4:31 pm

Hi all.
I am making an application thats consists of 2-3 activities and one more for the main menu.
Each of the 2-3 activities require my position to calculate distances, draw things on map etc.
My question is what is the right way to get my location.I mean i would prefer to get on the main screen when the application initialises and then pass it to the other activities whenever they are called. So the way to do that is to put it in extras when the activity is called? This means that by default my location will keep being updated as long as the application is running but only when i go back to the main screen I will get the new values?
spagi
Freshman
Freshman
 
Posts: 3
Joined: Wed May 05, 2010 4:24 pm

Top

Postby raim1312 » Wed May 05, 2010 9:33 pm

What I do is create a class that extends MyLocationOverlay. you can see the api for MyLocationOverlay here:
MyLocationOverlay API

My other activities simply create an instance of that custom class lets say MyCustomLocationOverlay and call getMyLocation() which returns a geopoint of the current location. For my version the constructor for my custom class accepts a context and a mapview
so in other words:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MyCustomLocationOverlay mlcOverlay = new MyCustomLocationOverlay(this, mapView);
  2. GeoPoint gpUser = mlcOverlay.getMyLocation();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
raim1312
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Apr 09, 2010 1:24 am
Location: RI

Postby spagi » Thu May 06, 2010 12:21 pm

Thanks alot for the reply

Since my location in my app isnt so crucial and it doesnt have to refresh alot, i wait on the main screen till I have an accurate fix and then pass my coordinates to the other activities with bundles.

Thanks again
spagi
Freshman
Freshman
 
Posts: 3
Joined: Wed May 05, 2010 4:24 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests