我正在我的应用程序中使用places API实现Google Maps。我需要这样,每当用户在编辑文本中键入地点时,地图就会为该特定地点设置动画。我已经实现了它并且工作正常。问题是如果我无法根据AutocompleteTextView中提到的位置控制缩放级别,例如,如果它是一个确切的地址,我想放大更多,如果它是一个状态,缩放应该不同,也是当它的a国家,它应相应地缩小。
我得到的长期为:
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 :(得分: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));
}
}