Location Listener not working

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

Location Listener not working

Postby akshaydashrath » Fri Jan 08, 2010 11:03 pm

Hello all,

I've implemented a location listener that executes a piece of code on location changed, but it does'nt seem to work, the location does not update on change of location for some reason.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  5.  
  6.         for (String p : locManager.getProviders(true))
  7.  
  8.             locManager.requestLocationUpdates(p, 0, 0,
  9.  
  10.                     Listing.this);
  11.  
  12.  
  13.  
  14. public void onLocationChanged(Location location) {
  15.  
  16.         System.err.println("In location changed-ListingActivity");
  17.  
  18.         super.onLocationChanged(location);
  19.  
  20.         refresh();
  21.  
  22.        
  23.  
  24.     }
  25.  
  26.  
  27.  
  28.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
akshaydashrath
Freshman
Freshman
 
Posts: 9
Joined: Mon Dec 14, 2009 11:38 pm
Location: UK

Top

Postby Draffodx » Mon Jan 11, 2010 3:16 pm

you have to update the location on the screen yourself

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /** Update the map with a new location */
  2.  
  3. private void updateWithNewLocation(Location location)
  4.  
  5. {
  6.  
  7. if (location != null) {
  8.  
  9. // Update my location marker
  10.  
  11. itemizedOverlay.setLocation(location);
  12.  
  13. // Update the map location.
  14.  
  15. Double geoLat = location.getLatitude()*1E6;
  16.  
  17. Double geoLng = location.getLongitude()*1E6;
  18.  
  19. GeoPoint point = new GeoPoint(geoLat.intValue(), geoLng.intValue());
  20.  
  21. controller.animateTo(point);
  22.  
  23. double lat = location.getLatitude();
  24.  
  25. double lng = location.getLongitude();
  26.  
  27.  latLongString = "Lat:" + lat + "\nLong:" + lng;
  28.  
  29.  }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests