I am trying to add map to a tab. I first did this with tabActivity, but since it is deprecated I decided to make it again using sliding tabs and navigation drawer. I followed this tutorial and managed to get it working, but now I have a problem - when I try moving the map with my fingers it becomes very slow, it drags, and moves only a little bit. Another problem I have is with zooming in/out - I can only zoom in when I double tap and cannot zoom out. Also, moving map up and down is disabled.
My map fragment:
public class MapsActivity extends Fragment {
private GoogleMap mMap;
MapView mapView;
Marker marker; // Marker
int markerCount = 0; // Marker counter
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflate and return the layout
View v = inflater.inflate(R.layout.activity_maps, container,
false);
mapView = (MapView) v.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMap = mapView.getMap();
mMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_me)));
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
int iMax = 5; // Max number of markers
@Override
public void onMapLongClick(LatLng arg0) {
if (markerCount < iMax) {
// start SendMessageActivity need to add marker to message activity
Intent intent = new Intent(getActivity(), SendInvitationActivity.class);
startActivity(intent);
markerCount = markerCount + 1;
marker = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_0))
.position(
new LatLng(arg0.latitude,
arg0.longitude))
.visible(true));
} else {
Toast.makeText(getActivity().getBaseContext(), "Only " + iMax + " markers allowed at the same time",
Toast.LENGTH_LONG).show();
}
}
});
return v;
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
and xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
So my problem is that my map reacts very poorly to finger input. It was not the case when I used TabActivity. I was wondering could this be the sliders problem - since I swipe tabs to move between them, could that "confuse" the map?
I tried doing this, but it did not work on map, it only disabled swiping between tabs.