J'ai programmé ce code dans Android Studio:plantages d'applications Android avec Google Maps objet
1) Karte.java
package barsoftware.suedtirolpointer;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class Karte extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap m_map;
boolean mapReady=false;
MarkerOptions Rieserfernerhütte;
MarkerOptions Dahoam;
static final CameraPosition SÜDTIROL = CameraPosition.builder()
.target(new LatLng(46.470576, 11.339986))
.zoom(8)
.bearing(0)
.tilt(0)
.build();
@Override
public Resources getResources() {
return super.getResources();
}
////////////////////////////// onCreate //////////////////////////////
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//// LAYOUT ////
setContentView(R.layout.karte);
//// KARTEN POI'S ////
Rieserfernerhütte = new MarkerOptions()
.position(new LatLng(46.5324, 12.0446))
.title("Rieserfernerhütte");
Dahoam = new MarkerOptions()
.position(new LatLng(46.738886, 12.166471))
.title("Dahoam");
//// KARTEN IMPLEMENTIERUNG ////
MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//// UP BOOTON ////
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
}
@Override
public void onMapReady(GoogleMap map) {
mapReady = true;
m_map = map;
m_map.addMarker(Rieserfernerhütte);
m_map.addMarker(Dahoam);
flyTo(SÜDTIROL);
}
private void flyTo(CameraPosition target)
{
m_map.moveCamera(CameraUpdateFactory.newCameraPosition(target));
}
////////////////////////////////// MENU //////////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_no_karte, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.menu_home) {
Intent Home = new Intent(Karte.this,
Start.class);
startActivity(Home);
}
if (id == R.id.menu_karte) {
}
if (id == R.id.menu_teilnehmer) {
Intent Teilnehmer = new Intent(Karte.this,
Teilnehmer.class);
startActivity(Teilnehmer);
}
if (id == R.id.menu_einstellungen) {
Intent Einstellungen = new Intent(Karte.this,
Einstellungen.class);
startActivity(Einstellungen);
}
if (id == R.id.menu_update) {
Intent Update = new Intent(Karte.this,
Update.class);
startActivity(Update);
}
if (id == R.id.menu_teilen) {
Intent Teilen = new Intent(Karte.this,
Teilen.class);
startActivity(Teilen);
}
return super.onOptionsItemSelected(item);
}
}
2) karte.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
3) Manifeste AndroidMais quand j'exécute l'application sur mon téléphone ou sur l'émulateur, l'appliation se bloque. Android-Studio ne montre aucune erreur ou bogue. Quelqu'un peut-il me montrer, quelle est l'erreur?
Quelle est l'erreur est à venir, postez l'erreur aussi. – Jarvis
@Jarvis Je ne reçois aucune erreur, mais l'application se bloque lors du lancement –