2016-04-07 8 views
-1

kullanarak kendi android uygulamasında google harita nasıl kendi android app google harita göstermek istiyorum ... Ben google map api anahtar getMapAsync() kullanarak manifest.im kullanarak .. ama değil çalışma .. şifre burada getMapAsync

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/map" 
      tools:context=".ClinicMap" 
      class="com.google.android.gms.maps.SupportMapFragment" 
      android:apiKey="AIzaSyCbtSjGcG1g2u9H-hfuO6Tx7F442ZndDb4"/> 
burada

... ben bana yardım done.please vardı en ufak hata .. teşekkür ederim orada altındadır benim ana faaliyettir

i MapFragment kullanıldığında
public class ClinicMap extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.clinic_map); 


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

//  MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); 
//  mapFragment.getMapAsync(this); 
} 

@TargetApi(Build.VERSION_CODES.M) 
@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    // Add a marker in Mumbai, India, and move the camera. 
    LatLng mumbai = new LatLng(19.0128, 72.8246); 
    if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     // TODO: Consider calling 
     // public void requestPermissions(@NonNull String[] permissions, int requestCode) 
     // here to request the missing permissions, and then overriding 
     // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
     //           int[] grantResults) 
     // to handle the case where the user grants the permission. See the documentation 
     // for Activity#requestPermissions for more details. 
     return; 
    } 
    mMap.setMyLocationEnabled(true); 
    //mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(mumbai)); 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mumbai, 4)); 
    mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
    mMap.addMarker(new MarkerOptions() 
      .title("mumbai") 
      .snippet("The most populous city in India.") 
      .position(mumbai)); 
    } 
} 

i boş üzerinde 'hükümsüz com.google.android.gms.maps.MapFragment.getMapAsync (com.google.android.gms.maps.OnMapReadyCallback)' "sanal yöntemi çağırmak girişimi hata var nesne referansı"

i SupportMapFragment
sen tuşu erişemez manifest dosyasında değilse, değil düzen dosyasında Manifest.xml API anahtarınızı koymak gerekir output will be like these

+0

herhangi hata alıyorum var burada http://stackoverflow.com/questions/27549521/googlemap-not-showing-the-changes-i-made –

+0

gelen örneği izleyin ?? catlog –

+0

no. @ Ravi Vaghela – Pratik

cevap

0

kullanıldığında harita servisine ve parçanıza hiçbir şey göstermeyecek. Bildirgenize gidin ve aşağıdaki satırları ekleyip eklemediğinizi kontrol edin.

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true"/> 

ve İÇİ <application> etiket:

<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" /> 

<meta-data 
android:name="com.google.android.maps.v2.API_KEY" 
android:value="API_KEY"/> 

Ayrıca genellikle ben bir null geçirerek değilim emin olmak için bu kod bloğunu kullanmak doğru oluşturulduktan mapFragment nesnesinin kontrol etmeniz gerekir getMapAsync() öğesine başvuru. belki sizin durumunuza sığdırmak bazı küçük düzeltme yapmak gerekir bu yüzden basit bir Fragment bu kullandım

fragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map_fragment); 
     if(fragment == null){ 
      FragmentManager manager = getFragmentManager(); 
      fragment =SupportMapFragment.newInstance(); 
      manager.beginTransaction().replace(R.id.map_fragment, fragment).commit(); 

     } 
     if (fragment != null){ 
      fragment.getMapAsync(this); 
     } 

, bir FragmentActivity var.

DÜZENLEME: Ben sınıf bir FragmentActivity, ben Fragment uzanan bir sınıfla eserler yazmış olduğunuz kodu uzanır olduğun fark ettik

.

  1. oluşturmak ve haritayı işlemek extends Fragment ve implements OnMapReadyCallback bir FragmentActivity ve başka sınıf oluşturun: Zihnimde Ben iki olası çözüm vardır.

  2. Düzeni içinde basit bir aktivite oluşturun, layout.xml bir parça oluşturun ve haritayı oluşturun. Bu durumda böyle bir şey olmalıdır:

MAP_LAYOUT.xml:

<FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <fragment 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/map" 
     tools:context=".MainActivity" 
     android:name="com.google.android.gms.maps.SupportMapFragment" /> 

</FrameLayout> 

ACTIVITY.java: Ben OnCreate(), SetUpMapIfYouNeed() ve SetUpMap() sadece ayrıntılar yazacağım

, bütün sınıf değil.

private GoogleMap mMap; // Might be null if Google Play services APK is not available. 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map_activity); 

     Bundle bundle = new Bundle(getIntent().getExtras()); 
     this.title = bundle.getString("name"); 
     setUpMapIfNeeded(); 
     //Other lines of code 
     //... 
     //... 
     } 


/** 
    * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly 
    * installed) and the map has not already been instantiated.. This will ensure that we only ever 
    * call {@link #setUpMap()} once when {@link #mMap} is not null. 
    * <p/> 
    * If it isn't installed {@link SupportMapFragment} (and 
    * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to 
    * install/update the Google Play services APK on their device. 
    * <p/> 
    * A user can return to this FragmentActivity after following the prompt and correctly 
    * installing/updating/enabling the Google Play services. Since the FragmentActivity may not 
    * have been completely destroyed during this process (it is likely that it would only be 
    * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this 
    * method in {@link #onResume()} to guarantee that it will be called. 
    */ 
    private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

/** 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, we 
    * just add a marker near Africa. 
    * <p/> 
    * This should only be called once and when we are sure that {@link #mMap} is not null. 
    */ 
    private void setUpMap() { 
     //mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
     mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 

     mMap.setMyLocationEnabled(true); 
     //Move the map to a specific point 


    } 
+0

Ayrıca çalışmayan manifest de api anahtarı ekledim. – Pratik

+0

Hala boş bir haritanız var mı yoksa boş nesne başvuru hatası mı aldınız? – Marco

+0

evet .. sadece boş bir harita .. – Pratik