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

Книгу можно купить на ЛитРес.
Всего за 490 руб. Купить полную версию
Шрифт
Фон

}

@Override

public void onMapReady (GoogleMap googleMap) {

mMap=googleMap;

// We create the world and fill the world

mWorld = CustomWorldHelper.generateObjects (this, mCurrentLocation);

// As we want to use GoogleMaps, we are going to create the plugin and

// attach it to the World

mGoogleMapPlugin = new GoogleMapWorldPlugin (this);

// Then we need to set the map in to the GoogleMapPlugin

mGoogleMapPlugin.setGoogleMap (mMap);

// Now that we have the plugin created lets add it to our world.

// NOTE: It is better to load the plugins before start adding object in to the world.

mWorld.addPlugin (mGoogleMapPlugin);

mMap.setOnMarkerClickListener (this);

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

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

// Lets add the user position

GeoObject user = new GeoObject (1000l);

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

user.setImageResource (R. drawable. flag);

user.setName («User position»);

mWorld.addBeyondarObject (user);

}

@Override

public void onConnected (@Nullable Bundle bundle) {

if (ActivityCompat.checkSelfPermission (this,

android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission (this, android.Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED) {

return;

}

Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation (mGoogleApiClient);

if (mLastLocation!= null) {

mCurrentLocation = mLastLocation;

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

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

Toast toast = Toast.makeText (this, «Last 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);

} 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.

Ваша оценка очень важна

0
Шрифт
Фон

Помогите Вашим друзьям узнать о библиотеке

Скачать книгу

Если нет возможности читать онлайн, скачайте книгу файлом для электронной книжки и читайте офлайн.

fb2.zip txt txt.zip rtf.zip a4.pdf a6.pdf mobi.prc epub ios.epub fb3