- Forum posts: 11
Aug 26, 2016, 9:13:33 AM via Website
Aug 26, 2016 9:13:33 AM via Website
=> I'm using following MapView in my layout:-
------------------------------------------------------------
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_gravity="bottom"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="@+id/ivLocation"
android:padding="1dp"
android:background="#D3D3D3"
map:liteMode="true"
/>
=> I have the following code in onCreateView() of fragment:-
MapsInitializer.initialize(this.getActivity());
mapView = (MapView) view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
mapView.setClickable(false);
=> And i also have the following code in the fragment class :-
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
if (ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
Location lastLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
LatLng latLng = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
map.addMarker(new MarkerOptions().position(latLng).title("City Coordinator location at login").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
map.getUiSettings().setMapToolbarEnabled(false);
}
This code is working in moto e2 phone with lollipop android, but not working in moto g3 phone with marshmallow android. In marshmallow, map is not loading at all in googlemap lite mode. If i remove this attribute( map:liteMode="true") in mapview, map is loading but marker is not present.
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.