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

Шрифт
Интервал



private GoogleMap mMap;

private GoogleMapWorldPlugin mGoogleMapPlugin;

private World mWorld;


@Override

protected void onCreate (Bundle savedInstanceState) {

super. onCreate (savedInstanceState);

setContentView(R.layout.map_google);


((SupportMapFragment) getSupportFragmentManager () .findFragmentById(R.id.map)).getMapAsync (this);


}


@Override

public boolean onMarkerClick (Marker marker) {

// To get the GeoObject that owns the marker we use the following

// 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);


// 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);

}

}

После запуска приложения на Android устройстве появится список с примерами.



Simple AR camera – показывает набор изображений на фоне камеры. При этом изображения расположены в пространстве вокруг устройства.

Simple camera with a max/min distance far for rendering – показывает набор изображений на фоне камеры с возможностью регулировки расстояния до изображений.

BeyondAR World in Google maps – показывает набор изображений на карте.

AR camera with Google maps – показывает набор изображений на фоне камеры с кнопкой переключения на карту.

Camera with touch events – показывает набор изображений на фоне камеры, а также сообщение при нажатии на одном из изображений.