2016-04-26 84 views
0

我在我的應用程序中使用Places API實施Google Maps。我需要的是,無論何時用戶在編輯文本中輸入地點,都要爲該地點設置動畫。我已經實現了它,並且工作正常。問題是如果我無法根據AutocompleteTextView中提到的位置控制縮放級別,例如,如果它的確切地址,我想放大更多,如果它的狀態,縮放應該不同,還有它的一個國家,它應該相應地縮小。如何根據地點控制Google地圖中的縮放級別

我得到的緯度只要:

private AdapterView.OnItemClickListener mAutocompleteClickListener = new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      final PlaceArrayAdapter.PlaceAutocomplete item = mPlaceArrayAdapter.getItem(position); 
      final String placeId = String.valueOf(item.placeId); 

      PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi 
        .getPlaceById(mGoogleApiClient, placeId); 
      placeResult.setResultCallback(mUpdatePlaceDetailsCallback); 

     } 
    }; 

    private ResultCallback<PlaceBuffer> mUpdatePlaceDetailsCallback = new ResultCallback<PlaceBuffer>() { 
     @Override 
     public void onResult(PlaceBuffer places) { 
      if (!places.getStatus().isSuccess()) { 

       return; 
      } 
      // Selecting the first object buffer. 
      final Place place = places.get(0); 
      place.getPlaceTypes(); 

      Log.d("Result Callback Hit", "Success"); 

      googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(),10)); 

     } 
    }; 
+0

你有緯度e和經度? –

+0

按照鏈接進行簡單的實施 http://stackoverflow.com/questions/32721896/zoom-function-google-maps –

+0

@YasirTahir:是的,我有經緯度 –

回答

0

您可以使用此方法將攝像機移動到任何點在地圖上

動畫:

private void moveToSelectedArea(LatLng position) { 
    if (googleMap != null) { 
     int ZOOM_LEVEL = 14; 
     // In your case, if you want to apply different zoom for different type, make a switch case based on type and set the zoom value 
     googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, ZOOM_LEVEL)); 
    } 
} 

無動畫:

private void moveToSelectedArea(LatLng position) { 
    if (googleMap != null) { 
     int ZOOM_LEVEL = 14; 
     // In your case, if you want to apply different zoom for different type, make a switch case based on type and set the zoom value 
     googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, ZOOM_LEVEL)); 
    } 
} 
+0

如何獲取類型? –

+0

如何將輸入的地址轉換爲經度和緯度?你有android.location.Address嗎? –

+0

使用PlaceArrayAdapter,放置API的谷歌 –

相關問題