2017-05-27 17 views
0

ちょっとAndroidスタジオで動作する位置情報サービスを取得しようとしています.getMapAsync(これ)がアプリをクラッシュさせています。誰かが私がどこを揺さぶっているかを私に見せることができれば、私はそれをとても感謝しています。getMapAsync(this)クラッシュを修正するには?

GoogleMap memberMap; 
GoogleApiClient memberAPI; 
LocationRequest memberLocationRequest; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if (googleServicesAvailable()) { 

     setContentView(R.layout.activity_main_page); 

     onMapReady(memberMap); 
    } else { 
     Toast.makeText(this, "Google services not available", Toast.LENGTH_LONG); 
     //to be done 
    } 
} 
@Override 
public void onMapReady(GoogleMap googleMap) { 
    memberMap = googleMap; 

    //memberMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
    SupportMapFragment mapFragment =(SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.mapfragment); 
    mapFragment.getMapAsync(this); 





    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
    if(!locationManager.isProviderEnabled((LocationManager.GPS_PROVIDER))){ 
     buildAlertMessageNoGps(); 
    } 

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
     if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { 
      buildGoogleApiClient(); 
      memberMap.setMyLocationEnabled(true); 
     } 
    } 

} 
+0

LogCatを使用して、クラッシュに関連するJavaスタックトレースを調べます。https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare

答えて

0

からgetMapAsync(this)を呼び出します。

は、以下のようにコードを更新します。

  1. Developing an Android app having Google Maps
  2. Google Map Tutorial in Android Studio: How to get current location in Android Google Map
  3. :ここ

    GoogleMap memberMap; 
    GoogleApiClient memberAPI; 
    LocationRequest memberLocationRequest; 
    
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        if (googleServicesAvailable()) { 
         setContentView(R.layout.activity_main_page); 
    
         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment); 
         mapFragment.getMapAsync(this); 
        } else { 
         Toast.makeText(this, "Google services not available", Toast.LENGTH_LONG); 
        } 
    } 
    
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
        memberMap = googleMap; 
    
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
        if(!locationManager.isProviderEnabled((LocationManager.GPS_PROVIDER))){ 
         buildAlertMessageNoGps(); 
        } 
    
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { 
          buildGoogleApiClient(); 
          memberMap.setMyLocationEnabled(true); 
         } else { 
          buildGoogleApiClient(); 
          memberMap.setMyLocationEnabled(true); 
         } 
        } 
    
        // Add markers 
        LatLng sydney = new LatLng(-34, 151); 
        memberMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
        memberMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 
    
    ................... 
    ............... 
    

    GoogleMapLocation APIについていくつかの良いチュートリアルです

関連する問題