Размер шрифта
-
+

Разработка Android-приложений с Augmented Reality - стр. 16

// method:

GeoObject geoObject = mGoogleMapPlugin.getGeoObjectOwner (marker);

if (geoObject!= null) {

Toast.makeText (this, «Click on a marker owned by a GeoOject with the name: " + geoObject.getName (),

Toast.LENGTH_SHORT).show ();

}

return false;

}


@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 let’s 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);

Страница 16