gps problem

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

gps problem

Postby microhome » Mon May 11, 2009 12:04 pm

Hi everybody,
first of all I want you to know, that anddev is a really great project and I hope, that it will become more and more known :)

I tried to play around with that interesting gps function of android, here is my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.gps;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.content.Context;
  8.  
  9. import android.location.Location;
  10.  
  11. import android.location.LocationListener;
  12.  
  13. import android.location.LocationManager;
  14.  
  15. import android.os.Bundle;
  16.  
  17. import android.widget.TextView;
  18.  
  19.  
  20.  
  21. public class gps extends Activity
  22.  
  23. {
  24.  
  25.     private LocationManager lm;
  26.  
  27.     private LocationListener locationListener;
  28.  
  29.  
  30.  
  31.     /** Called when the activity is first created. */
  32.  
  33.     @Override
  34.  
  35.     public void onCreate(Bundle savedInstanceState) {
  36.  
  37.         super.onCreate(savedInstanceState);
  38.  
  39.         setContentView(R.layout.main);
  40.  
  41.        
  42.  
  43.         //---use the LocationManager class to obtain GPS locations---
  44.  
  45.         lm = (LocationManager)
  46.  
  47.             getSystemService(Context.LOCATION_SERVICE);    
  48.  
  49.        
  50.  
  51.         locationListener = new MyLocationListener();
  52.  
  53.        
  54.  
  55.         lm.requestLocationUpdates(
  56.  
  57.             LocationManager.GPS_PROVIDER,
  58.  
  59.             0,
  60.  
  61.             0,
  62.  
  63.             locationListener);        
  64.  
  65.     }
  66.  
  67.    
  68.  
  69.     private class MyLocationListener implements LocationListener
  70.  
  71.     {
  72.  
  73.         @Override
  74.  
  75.         public void onLocationChanged(Location loc) {
  76.  
  77.                 TextView tv = new TextView(gps.this);
  78.  
  79.             tv.setText("Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude());
  80.  
  81.             setContentView(tv);
  82.  
  83.         }
  84.  
  85.  
  86.  
  87.         @Override
  88.  
  89.         public void onProviderDisabled(String provider) {
  90.  
  91.             // TODO Auto-generated method stub
  92.  
  93.         }
  94.  
  95.  
  96.  
  97.         @Override
  98.  
  99.         public void onProviderEnabled(String provider) {
  100.  
  101.             // TODO Auto-generated method stub
  102.  
  103.         }
  104.  
  105.  
  106.  
  107.         @Override
  108.  
  109.         public void onStatusChanged(String provider, int status,
  110.  
  111.             Bundle extras) {
  112.  
  113.             // TODO Auto-generated method stub
  114.  
  115.         }
  116.  
  117.     }        
  118.  
  119.    
  120.  
  121. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


But I have two problems and it would be great, if we could solve them.

1. I can't update my GPS position by Eclipse (DDMS). Only via telnet "geo fix" - but why??
2. My application only shows the first location change. Afterwards nothing happens - why??


Thank you very much for your help and best regards from Berlin.
microhome
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 10, 2009 8:49 pm
Location: Berlin, Germany

Top

Postby hristo » Mon May 11, 2009 3:24 pm

Hi microhome,

1. I can't update my GPS position by Eclipse (DDMS). Only via telnet "geo fix" - but why??

I had the same problem and it was for a locale problem. See this link: http://code.google.com/p/android/issues/detail?id=915

2. My application only shows the first location change. Afterwards nothing happens - why??
I have the same problem since I updated the sdk version to 1.5. With the sdk 1.1 my code worked fine. I don't know how to solve it yet.
hristo
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 11, 2009 3:16 pm

Postby microhome » Mon May 11, 2009 3:41 pm

Hi hristo,
thanks for your response. The cause of problem 1 was the decimal char. The English one is a dot but here in Germany it is a comma. As in that google issue posted, the only way to solve this problem is changing windows standard and format layout to English.

I'm using SDK 1.5, too and I have definitely no idea about the second problem. Anyone else?


Thank you very much!
microhome
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 10, 2009 8:49 pm
Location: Berlin, Germany

Postby velocity » Thu Jun 04, 2009 9:55 am

I'm experiencing the same Problem with SDK 1.5 I get the location update only once , has anyone solved this problem yet ?
velocity
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Aug 19, 2008 12:05 pm

Postby piuccio » Sun Sep 06, 2009 11:57 am

I get the same error.
I tried to override this function in the listener
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3. public void onStatusChanged(String provider, int status, Bundle extras) {
  4.  
  5.         Log.w(TAG, "onStatusChanged "+provider+" is in statuts "+status);
  6.  
  7.         Set<String> keys = extras.keySet();
  8.  
  9.         for (String key: keys) {
  10.  
  11.                 Log.i(TAG, "[extras] "+key+": "+extras.get(key));
  12.  
  13.         }
  14.  
  15.         if (provider.equals(LocationManager.GPS_PROVIDER) && status == GpsStatus.GPS_EVENT_STOPPED) {
  16.  
  17.                 Log.e(TAG, "Gps disabled");
  18.  
  19.         }
  20.  
  21. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

and it's called twice
the first time the status is 1 -> GPS_EVENT_STARTED
immediately later it's called again with status 2 -> GPS_EVENT_STOPPED
piuccio
Freshman
Freshman
 
Posts: 3
Joined: Sun Sep 06, 2009 11:43 am

Postby piuccio » Mon Sep 07, 2009 11:25 am

piuccio
Freshman
Freshman
 
Posts: 3
Joined: Sun Sep 06, 2009 11:43 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests