2017-08-04 10 views
0

現在、私は自分のプロジェクトでGoogleマップに取り組んでいます。 私は以下のAPIバージョンとGoogleマップのディスプレイを使用しています。Googleマップのズーム機能が動作しません

android.gms:play-services-maps:9.0.2 
android.gms:play-services-location:9.0.2 

問題:

私はタッチでマップをズームしようとすると、グーグルマップがズームしないと 私も別の場所を見るためにマップを移動することができませんでしだ。

は、ここに私のコードです:

@Override 
public void onMapReady(GoogleMap googleMap) { 

    //googleMap.getUiSettings().setZoomControlsEnabled(true); 

    mMap = googleMap; 

    Log.i(TAG, "onMapReady"); 


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
        Toast.makeText(this,"Please enable GPS location on your phone",Toast.LENGTH_SHORT).show(); 

     return; 
    } 
    Log.i(TAG, "my location enabled"); 


    mMap.setMyLocationEnabled(true); 
    map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null); 

    buildGoogleApiClient(); 
    if (mMap == null) { 
     return; 
    } 
    /* currentLatLng= new LatLng (currentLocationLatitude,currentLocationLongitude); 
    Log.i(TAG,"inside onMapready --->");*/ 

} 

protected synchronized void buildGoogleApiClient() { 

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(LocationServices.API) 
      .build(); 
    mGoogleApiClient.connect(); 

} 

* XMLファイルが含まれている* これは私がGoogleマップを表示するために使用していた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_height="match_parent" 
android:layout_width="match_parent" 
android:orientation="horizontal" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<fragment android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.mega.hertz.seeky.MainActivity"/> 

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/vertical_page_margin" 
    android:paddingLeft="@dimen/horizontal_page_margin" 
    android:paddingRight="@dimen/horizontal_page_margin" 
    android:paddingTop="@dimen/margin_small"> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="50dp"> 

    <fragment 
     android:id="@+id/autocomplete_fragment" 
     android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</android.support.v7.widget.CardView> 


</LinearLayout> 
</ScrollView> 

+0

がhiそこに、私はxmlファイル –

+0

あなたのXMLファイルを共有します私はそれが動作していないとまた、私はマップを基本的に移動することはできませんマップ上の指のタッチは動作していません – user1439582

答えて

0

あなたのコード内の関数の下に追加します。

@Override 
public void onLocationChanged(Location location) { 
    double latitude = location.getLatitude(); 
    double longitude = location.getLongitude(); 

    LatLng latLng = new LatLng(latitude, longitude); 
    mMap.addMarker(new MarkerOptions().position(latLng).title("My Location")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
    mMap.animateCamera(CameraUpdateFactory.zoomTo(20));  
} 
+0

が含まれているこのソリューションは、マップがloaded.my問題がGoogleマップの後にロードされることであるときにレベルをズームするマップを移動 – user1439582

0

ScrollViewの下部にフラグメントを追加するだけです。マップフラグメントはScrollViewによってオーバーラップされるためです。以下のようなあなたのXMLを変更 :

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

</ScrollView> 

<fragment android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.mega.hertz.seeky.MainActivity"/> 
+0

私はスクロールビューの後にGoogleマップの断片を入れ、コードをコンパイルし、UIを確認すると、placeautocimpletefragment表示されず、Googleマップのみが表示されますが、ズームできます。私は断片plaveautofragmentを使用してGoogleの場所の検索が必要 – user1439582

+0

"PlaceAutocompleteFragment"のためにあなたのコードを共有してください。 このリンクも参照できます:https://developers.google.com/places/android-api/autocomplete –

+0

ありがとうございます。私のコードは です。PlaceAutocompleteFragment autocompleteFragment =(PlaceAutocompleteFragment) getFragmentManager()。findFragmentById(R.id.autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(this);(EditText)autocompleteFragment.getView()。findViewById(R.id.place_autocomplete_search_input))。setTextSize(15.0f); – user1439582

関連する問題