Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For some reason (unknown to me), moving the map initialization from onCreate() into the first invocation of onLocationChange() did the trick. Now my onCreate() is simply</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.map_activity); } </code></pre> <p>my onStart() is:</p> <pre><code>@Override protected void onStart() { super.onStart(); // Create the LocationRequest object mLocationRequest = LocationRequest.create(); // Use high accuracy mLocationRequest.setPriority( LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the update interval to 5 seconds mLocationRequest.setInterval(UPDATE_INTERVAL); // Set the fastest update interval to 1 second mLocationRequest.setFastestInterval(FASTEST_INTERVAL); mLocationClient = new LocationClient(this, this, this); mLocationClient.connect(); } @Override public void onConnected(Bundle arg0) { mLocationClient.requestLocationUpdates(mLocationRequest, this); } </code></pre> <p>and my onLocationChange() is</p> <pre><code>@Override public void onLocationChanged(Location loc) { if (mMap == null) { mapFragment = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = getSupportFragmentManager() .beginTransaction(); fragmentTransaction.add(R.id.mapcontainer, mapFragment); fragmentTransaction.commit(); mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); mMap.getUiSettings().setAllGesturesEnabled(true); mMap.getUiSettings().setMyLocationButtonEnabled(true); mMap.getUiSettings().setZoomControlsEnabled(true); mMap.getUiSettings().setCompassEnabled(true); mMap.setMyLocationEnabled(false); LatLng location = new LatLng(loc.getLatitude(), loc.getLongitude()); CameraPosition pos = new CameraPosition.Builder().target(location).zoom(12).build(); CameraUpdate cu = CameraUpdateFactory.newCameraPosition(pos); mMap.animateCamera(cu); if (mLocationClient.isConnected()) mLocationClient.removeLocationUpdates(this); mLocationClient.disconnect(); Log.e(getClass().getSimpleName(), "lat = " + location.latitude + " long = " + location.longitude); } } </code></pre> <p>It works, but now I have a different problem (the map seems to ignore touch events). I'm going to create a separate question for that.</p>
 

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