Я реализовал фрагмент карты Google в классе пользовательских настроек. И карта не работает должным образом. Кажется, что он слушает только в центре карты.
Вот код:
location_preference.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:textColor="#000"
android:id="@+id/location_pref_input"
android:background="@color/White" />
android:textSize="16sp"
android:hint="Enter Address, City or Zip Code"
android:imeOptions="actionSearch" />
<FrameLayout
android:id="@+id/preference_map_fragment"
android:layout_width="match_parent"
android:layout_height="370dp" />
</LinearLayout>
LocationPreference.java
public class LocationPreference extends Preference implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener {
private static final String TAG = "LocationPreference";
private Context mContext;
private MapFragment mapFragment;
private GoogleMap mMap;
private View rootView;
public LocationPreference(Context context) {
super(context);
setLayoutResource(R.layout.location_preference);
mContext = context;
}
public LocationPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
setLayoutResource(R.layout.location_preference);
mContext = context;
}
public LocationPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setLayoutResource(R.layout.location_preference);
mContext = context;
}
@Override
public View onCreateView(ViewGroup parent) {
super.onCreateView(parent);
LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rootView = li.inflate(R.layout.location_preference, parent, false);
AppCompatActivity prefActivity = (AppCompatActivity) mContext;
if (mapFragment == null) {
mapFragment = new MapFragment();
prefActivity.getFragmentManager().beginTransaction()
.replace(R.id.preference_map_fragment, mapFragment)
.commit();
mapFragment.getMapAsync(this);
}
return rootView;
}
... есть некоторые переопределенные методы, которые пусты: onConnected, onConnectionSuspended, onConnectionFailed, onLocationChanged
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Toast.makeText(mContext, "onMapReady",
Toast.LENGTH_LONG).show();
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(sydney).zoom(19f).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
Это добавляется к фрагменту настроек через addPreferencesFromResource ().
Я не уверен, в чем проблема, потому что я теряюсь в использовании хакерских способов добиться того, чего я хочу. Я не мог найти какую-либо помощь онлайн по этой проблеме.
Я действительно не знаю, в чем может быть проблема, поэтому, если вам нужна дополнительная информация или больше кода, я поделюсь им.