2017-08-04 72 views
0

目前我正在處理我的項目中的谷歌地圖。 我正在使用下面的API版本和谷歌地圖顯示。谷歌地圖縮放功能無法正常工作

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文件包括* 這是我使用的顯示谷歌地圖的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

分享您的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問題的地圖,此前谷歌地圖是裝當我縮放它不工作,我也無法移動地圖基本上手指觸摸地圖不起作用 – 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

當我把谷歌地圖的片段後滾動視圖和編譯代碼並檢查用戶界面,placeautocimpletefragment谷歌搜索地點沒有出現,只有谷歌地圖出現,但我可以放大。我需要谷歌地方搜索使用片段plaveautofragment – 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