Разработка Android-приложений с Augmented Reality. Тимур Машнин
Чтение книги онлайн.

Читать онлайн книгу Разработка Android-приложений с Augmented Reality - Тимур Машнин страница 14

СКАЧАТЬ style="font-size:15px;">      mMap.clear ();

      mWorld = CustomWorldHelper.generateObjects (this, mCurrentLocation);

      mGoogleMapPlugin = new GoogleMapWorldPlugin (this);

      mGoogleMapPlugin.setGoogleMap (mMap);

      mWorld.addPlugin (mGoogleMapPlugin);

      mMap.setOnMarkerClickListener (this);

      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mGoogleMapPlugin.getLatLng (), 15));

      mMap.animateCamera (CameraUpdateFactory. zoomTo (19), 2000, null);

      GeoObject user = new GeoObject (1000l);

      user.setGeoPosition(mWorld.getLatitude (), mWorld.getLongitude ());

      user.setImageResource (R. drawable. flag);

      user.setName («User position»);

      mWorld.addBeyondarObject (user);

      } else {

      startLocationUpdates ();

      }

      }

      @Override

      public void onConnectionSuspended (int i) {

      }

      @Override

      public void onConnectionFailed (@NonNull ConnectionResult connectionResult) {

      }

      @Override

      public void onLocationChanged (Location location) {

      mCurrentLocation = location;

      String lat = String.valueOf(mCurrentLocation.getLatitude ());

      String lon = String.valueOf(mCurrentLocation.getLongitude ());

      Toast toast = Toast.makeText (this,«Current location " + lat+" "+lon, Toast. LENGTH_LONG);

      toast.show ();

      mWorld.clearWorld ();

      mMap.clear ();

      mWorld = CustomWorldHelper.generateObjects (this, mCurrentLocation);

      mGoogleMapPlugin = new GoogleMapWorldPlugin (this);

      mGoogleMapPlugin.setGoogleMap (mMap);

      mWorld.addPlugin (mGoogleMapPlugin);

      mMap.setOnMarkerClickListener (this);

      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mGoogleMapPlugin.getLatLng (), 15));

      mMap.animateCamera (CameraUpdateFactory. zoomTo (19), 2000, null);

      GeoObject user = new GeoObject (1000l);

      user.setGeoPosition(mWorld.getLatitude (), mWorld.getLongitude ());

      user.setImageResource (R. drawable. flag);

      user.setName («User position»);

      mWorld.addBeyondarObject (user);

      }

      }

      import android.content.pm.PackageManager;

      import android. location. Location;

      import android. os. Bundle;

      import android.support.annotation.NonNull;

      import android.support.annotation.Nullable;

      import android.support.v4.app.ActivityCompat;

      import android.support.v4.app.FragmentActivity;

      import android.view. Window;

      import android.widget.Toast;

      import com.beyondar.android.fragment.BeyondarFragmentSupport;

      import com.beyondar.android. opengl. util. LowPassFilter;

      import com.beyondar.android. world. World;

      import com.google.android.gms.common.ConnectionResult;

      import com.google.android.gms.common. api. GoogleApiClient;

      import com.google.android.gms. location. LocationListener;

      import com.google.android.gms. location. LocationRequest;

      import com.google.android.gms. location. LocationServices;

      public class SimpleCameraActivity extends FragmentActivity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient. OnConnectionFailedListener {

      private BeyondarFragmentSupport mBeyondarFragment;

      private World mWorld;

      GoogleApiClient mGoogleApiClient;

      Location mCurrentLocation;

      LocationRequest mLocationRequest;

      /** Called when the activity is first created. */

      @Override

      public void onCreate (Bundle savedInstanceState) {

      super. onCreate (savedInstanceState);

      // Hide the window title.

      requestWindowFeature (Window. FEATURE_NO_TITLE);

      setContentView(R.layout.simple_camera);

      mBeyondarFragment = (BeyondarFragmentSupport) getSupportFragmentManager () .findFragmentById(R.id.beyondarFragment);

      // We also can see the Frames per seconds

      mBeyondarFragment.showFPS (false);

      // We create the world and fill it…

      mWorld = CustomWorldHelper.generateObjects (this, mCurrentLocation);

      // … and send it to the fragment

      mBeyondarFragment.setWorld (mWorld);

      LowPassFilter.ALPHA = 0.003f;

      buildGoogleApiClient ();

      }

      /**

      * Builds a GoogleApiClient. Uses the {@code #addApi} method to request the

      * LocationServices API.

      */

СКАЧАТЬ