Map GPS display

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

Map GPS display

Postby BeerBelly » Thu Mar 11, 2010 4:02 pm

Hey, first of all I'd like to say I enjoy this site.

Second...I've run into a problem :)

I'm trying to write an app that draws markers on the map each time your location changes. Using GPS of course.

Code as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private Spinner radius;
  3.  
  4.         private MapView karta;
  5.  
  6.         private LinearLayout layout;
  7.  
  8.         private ZoomControls mZoom;
  9.  
  10.         private List<Overlay> mapOverlays;
  11.  
  12.         private Drawable icon;
  13.  
  14.         private Markers mapMarkers;
  15.  
  16.         private LocationManager GPSHandler;
  17.  
  18.         private Location myLocation;
  19.  
  20.         private LocationProvider locProvider;
  21.  
  22.         private LocationListener llistener;
  23.  
  24.         private MapController mc;
  25.  
  26.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Listener class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. LocationListener llistener = new LocationListener() {
  3.  
  4.                        
  5.  
  6.                         @Override
  7.  
  8.                         public void onStatusChanged(String provider, int status, Bundle extras) {
  9.  
  10.                                 // TODO Auto-generated method stub
  11.  
  12.                                 //Toast.makeText(getBaseContext(), status, Toast.LENGTH_SHORT).show();
  13.  
  14.                         }
  15.  
  16.                        
  17.  
  18.                         @Override
  19.  
  20.                         public void onProviderEnabled(String provider) {
  21.  
  22.                                 // TODO Auto-generated method stub
  23.  
  24.                                
  25.  
  26.                         }
  27.  
  28.                        
  29.  
  30.                         @Override
  31.  
  32.                         public void onProviderDisabled(String provider) {
  33.  
  34.                                 // TODO Auto-generated method stub
  35.  
  36.                                
  37.  
  38.                         }
  39.  
  40.                        
  41.  
  42.                         @Override
  43.  
  44.                         public void onLocationChanged(Location location) {
  45.  
  46.                                 // TODO Auto-generated method stub
  47.  
  48.                                 Toast.makeText(getBaseContext(), "Location changed", Toast.LENGTH_SHORT).show();
  49.  
  50.                                 if (location != null) {                
  51.  
  52.                        
  53.  
  54.                        
  55.  
  56.                         GeoPoint p = new GeoPoint(
  57.  
  58.                                 (int) (location.getLatitude() * 1E6),
  59.  
  60.                                 (int) (location.getLongitude() * 1E6));
  61.  
  62.                         mc.animateTo(p);
  63.  
  64.                         mc.setZoom(16);    
  65.  
  66.                         OverlayItem item = new OverlayItem(p,"","");
  67.  
  68.                                
  69.  
  70.                                 mapMarkers.addOverlay(item);
  71.  
  72.                                 mapMarkers.setFocus(item);
  73.  
  74.                                 mapOverlays.add(mapMarkers);
  75.  
  76.                         //karta.invalidate();
  77.  
  78.                     }
  79.  
  80.  
  81.  
  82.                         }
  83.  
  84.                 };
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Settting up GPS:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. karta = (MapView) findViewById(R.id.mapview);
  3.  
  4.         mc = karta.getController();
  5.  
  6.         karta.setBuiltInZoomControls(true);
  7.  
  8.        
  9.  
  10.         mapOverlays = karta.getOverlays();
  11.  
  12.         icon = this.getResources().getDrawable(R.drawable.arrow);
  13.  
  14.         mapMarkers = new Markers(icon);
  15.  
  16.        
  17.  
  18.        
  19.  
  20.        
  21.  
  22.         GPSHandler = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  23.  
  24.        
  25.  
  26.        
  27.  
  28.        
  29.  
  30.        
  31.  
  32.         GPSHandler.requestLocationUpdates(GPSHandler.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE, llistener);
  33.  
  34.        
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I'm querying last known location as well and it's returning one. The onLocationChanged fires only once at the start and then not anymore (I'm loading a GPX file in the DDMS view). Any idea what I'm doing wrong?

Thanks for all the help.
BeerBelly
Freshman
Freshman
 
Posts: 5
Joined: Thu Mar 11, 2010 3:54 pm

Top

Postby BeerBelly » Tue Mar 16, 2010 2:24 pm

To answer my own question...the problem was in locale settings. I had to add a line to Eclipse.ini to use english as locale used for dispaying and using numbers.
BeerBelly
Freshman
Freshman
 
Posts: 5
Joined: Thu Mar 11, 2010 3:54 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 6 guests