Problem with getting GPS Position

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

Problem with getting GPS Position

Postby Marcel » Sun Jan 20, 2008 8:08 pm

Hi all,

I am trying to build a test app which shows the current position @ google maps. The Android Docs say that the emulator simulates a journey somewhere in san francisco. But all I get vom getLatitude() and getLongitude() is just "0.0".

Here's the code with the test output I used (which is always "Lat: 0.0 - Lon: 0.0"):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. LocationManager myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  3.  
  4.  
  5.  
  6. Location gpsLocation = myLocationManager.getCurrentLocation("gps");
  7.  
  8.  
  9.  
  10. Double lat = gpsLocation.getLatitude() * 1E6;
  11.  
  12. Double lon = gpsLocation.getLongitude() * 1E6;
  13.  
  14.  
  15.  
  16. TextView txt = (TextView)findViewById(R.id.txt);
  17.  
  18. txt.setText("Lat: " + lat + " - Lon: " + lon);
  19.  
  20.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Does someone have the same problem or did I just miss something? :S
Marcel
Freshman
Freshman
 
Posts: 9
Joined: Sun Jan 20, 2008 7:49 pm
Location: Germany

Top

Postby plusminus » Sun Jan 20, 2008 8:13 pm

Hello Marcel,

unfortunately I have no time now to explore your code.
But you should take a look at the :src: FriendFinder-Tutorial. Exactly the same is done there and it is working.

Hope I could help you. :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Marcel » Mon Jan 21, 2008 7:57 pm

Hey plusminus,

I checked your tutorial and found the solution for my problem. It looks like you have to register the LocationProvider @ LocationManager.requestUpdates and then wait for an intent to be fired.

If someone knows another way please let me know...
Marcel
Freshman
Freshman
 
Posts: 9
Joined: Sun Jan 20, 2008 7:49 pm
Location: Germany

Postby wonglik » Tue Feb 12, 2008 6:49 pm

Hi Marcel I have similar problem.
You mention about registering locationProvider with requestUpdate but documentation states
Registers the current activity to be notified periodically by the named provider
so I am not sure if this is required. Did You manage to overcome Your problem? Can You post Your solution?


regards
Mateusz
wonglik
Freshman
Freshman
 
Posts: 8
Joined: Tue Feb 12, 2008 6:35 pm
Location: Poland

Postby Marcel » Tue Feb 12, 2008 7:18 pm

Hi wonglik,

I didn't work on that problem since my last post. But I read somewhere that when you call getCurrentLocation("gps"); a second time it gives you the correct gps position. The first call just triggers that San Francisco journey but still returns 0 for getLatitude(); and getLongitude();. Haven't tested it yet but if you do so please post your results here ;-). Maybe the next SDK release will bring some clarity...
Marcel
Freshman
Freshman
 
Posts: 9
Joined: Sun Jan 20, 2008 7:49 pm
Location: Germany

Postby wonglik » Thu Feb 14, 2008 6:30 pm

Hi Marcel

Well I am still not sure how it works. If You make two locationManager.getCurrentLocation("gps") request in a row it still do not gives correct values. However if You register an Intent

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. this.locationManager.requestUpdates(provider,
  3.  
  4.                                 MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE,
  5.  
  6.                                 new Intent(MY_LOCATION_CHANGED_ACTION));
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


It will work. Not sure what is the reason behind that.

regards
Mateusz
wonglik
Freshman
Freshman
 
Posts: 8
Joined: Tue Feb 12, 2008 6:35 pm
Location: Poland

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests