hier ist die komplette Activity.
Ich sehe nur eine Instanz der Map
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
//import android.support.v4.app.FragmentTransaction;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
public class PKarte extends FragmentActivity implements android.location.LocationListener{
private MapView mapView;
private MyLocationOverlay myLocationOverlay;
public boolean autozoom = false;
private GoogleMap googleMap;
CameraPosition cameraPosition;
TextView tvLocation;
LocationManager locationManager;
private int kartentype = 1;
/** Called when the activity is first created. */
/*************************************************************************************
*
* onCreate
*
************************************************************************************/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// main.xml contains a MapView
setContentView(R.layout.map_layout);
tvLocation = (TextView) findViewById(R.id.tv_location);
}
/*************************************************************************************
*
* onResume
*
************************************************************************************/
@Override
protected void onResume() {
super.onResume();
/**********************************************
* relevante Benutzereinstellungen lesen
*
**********************************************/
SharedPreferences getEinstellungen = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
kartentype = Integer.valueOf(getEinstellungen.getString("karteneinstellungen1","1"));
karteAnzeigen();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// .target(latLng) // Sets the center of the map to Mountain View
// Setting latitude and longitude in the TextView tv_location
tvLocation.setText("Latitude:" + latitude + ", Longitude:"+ longitude );
cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(),location.getLongitude()))
.zoom(15) // Sets the zoom
.bearing(180) // Sets the orientation of the camera to xy
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
locationManager.removeUpdates(this);
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
/**************************************************************
* Karte anzeigen
*
*************************************************************/
private void karteAnzeigen() {
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else { // Google Play Services are available
// Getting reference to the SupportMapFragment of amap_layout.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
/* zur internen Info Integerwerte
* GoogleMap.MAP_TYPE_NORMAL = 1
* GoogleMap.MAP_TYPE_SATELLITE = 2
* GoogleMap.MAP_TYPE_TERRAIN = 3
* GoogleMap.MAP_TYPE_HYBRID = 4;
*/
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().isTiltGesturesEnabled();
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
googleMap.setMapType(kartentype);
// Getting LocationManager object from System Service LOCATION_SERVICE
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);
LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
// Showing the current location in Google Map
if(location!=null){
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
// locationManager.requestLocationUpdates(provider, 10000, 0, this); // 10 sec
}
}
/****************************************************************************************************
*
* Komplettes Menuehandling
******************************************************************************************************/
// Menuehandling
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.karten_menue1, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.itemKarteneinstellungen:
startActivity(new Intent(this, Karteneinstellungen.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
[/code]
EDIT: drumliner ich hab mal das
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
rausgenommen, setzt mich jetz mal ins auto und will sehen ob das die Ursache ist
EDIT2: was verhagelt denn hier die Code-tags ??