ロケーション マネージャーから位置情報の更新を削除しようとしましたが、removeupdates が呼び出された後でも GPS シンボルが引き続き表示されます。正しいリスナー変数名が渡され、リスナーの更新のためにコードが実行されることを確認しました。ユーザーの場所を一度だけ見つけたい。
ありがとう
public class MapActivity extends FragmentActivity implements OnInfoWindowClickListener, OnCameraChangeListener {
Map<Marker, Integer> markers = new HashMap<Marker, Integer>();
VenueManager venueManager;
GoogleMap map;
long last_map_refresh = 0;
Button search_btn;
CameraPosition previous_position = null;
private LocationManager locationManager;
private static final long MIN_TIME = 400;
private static final float MIN_DISTANCE = 1000;
private ProgressDialog loading;
private Button add_venue;
SharedPreferences sharedPreferences;
private LatLng user_position = null;
private NetworkManager network_manager;
private Boolean first_map_render = false;
private LocationListener location_listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if( !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ) {
AlertDialog.Builder builder = new AlertDialog.Builder(MapActivity.this);
builder.setTitle("GPS not enabled"); // GPS not found
builder.setMessage("This application requires you to enable GPS location settings. We recommend that you enable 'Use wireless networks' and 'Use GPS satellites'. Would you like to enable this setting now?"); // Want to enable?
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
finish();
MapActivity.this.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
Intent home_intent = new Intent(MapActivity.this, HomeActivity.class);
startActivity(home_intent);
Toast.makeText(MapActivity.this, "You will not be able to use the map features of this application until you enable gps settings", Toast.LENGTH_LONG).show();
finish();
}
});
builder.create().show();
return;
}
else
{
network_manager = new NetworkManager();
location_listener = new LocationListener() {
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 16);
map.animateCamera(cameraUpdate);
draw_map(new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude())).build());
user_position = latLng;
locationManager.removeUpdates(location_listener);
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, location_listener);
}
}