Note that there are some explanatory texts on larger screens.

plurals
  1. PORegarding current location in android
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1389811/gps-not-update-location-after-close-and-reopen-app-on-android">GPS not update location after close and reopen app on android</a> </p> </blockquote> <p>I know that question is asked already but my problem is that.</p> <p>every time when I open my app it shows last location not current location</p> <p>I have a button for current location and i want when i open my app it show current location on map after then when I click on button then it show current location. </p> <p>so my problem is when i open my app it shows last location but when i press then it shows current location.</p> <p><strong>code in onCreate()</strong></p> <pre><code>_locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); _locationListener = new CurrentLocationListener(this,this); _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,1,_locationListener ); _currentGeoPoint = getKnownLocation(); _currentPosOverlay = new OverlayItem(_currentGeoPoint, "", ""); Log.d(" overlay", "overlaylast "+_currentGeoPoint); // Toast.makeText(getBaseContext(), "overlay12333vvv "+_currentGeoPoint, Toast.LENGTH_SHORT).show(); _customOverlay.addOverlay(_currentPosOverlay); _mapOverlays.add(_customOverlay); </code></pre> <p><strong>Code for getKnownLocation()</strong></p> <pre><code> // TODO Auto-generated method stub Location lastLocation = _locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(lastLocation == null){ lastLocation = _locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } if(lastLocation != null){ GeoPoint gp = new GeoPoint((int)(lastLocation.getLatitude() * 1e6), (int)(lastLocation.getLongitude() * 1e6)); last_loc=gp; return gp; }else { return _mapView.getMapCenter(); } </code></pre> <p><strong>For the button I called getKnownLocation()</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload