I have in an Fragment
implemented Google API
and WORKS . But it works on my 3 phones which are jellybean , kitkat and lollipop . My friend's, which is 6.0 , does not work ... the map of GOOGLE API
, yes, appears, but the coordinates do not appear, as if he had not put anything, only the map...
Because ? Where does it fail?
Clarification : If you are thinking of telling me to try MapFragment
the application stops me, so that is not the solution, MapFragment
instead of SupportMapFragment
it does not work for me in any situation, and what is implemented here below works:
public class Map_fragment extends Fragment implements OnMapReadyCallback {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_map, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager().findFragmentById(R.id.mapid);
mapFragment.getMapAsync(this);
return v;
}
@Override
public void onMapReady(GoogleMap map) {
LatLng RudeBoys = new LatLng(39.4561165, -0.3545661);
LatLng Malaga = new LatLng(36.6981483, -4.4513236);
LatLng Melilla = new LatLng(35.2896931, -2.9427164);
if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(RudeBoys, 5)); // ZOOM AL EMPEZAR EL GOOGLE MAP
// ¡¡ FOR EACH LOCATION I CAN USE DIFFERENT ICON AND DESCRIPTION , RAFA!!
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.box24))
.title("Rude-Boys")
.snippet("Tienda principal")
.position(RudeBoys));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mapfinal))
.title("CLUB DE LA LUCHA")
.snippet("Málaga")
.position(Malaga));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mapfinal))
.title("ON FITNESS SHOP")
.snippet("Melilla")
.position(Melilla));
}
}
<fragment
android:id="@+id/mapid"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
From Android 6.0 onwards, the permissions of the applications are not given when it is installed, but when the user occupies it. To access the coordinates of the phone it is necessary to see the necessary permissions. You could see with this Documentation :
EDITION
If it's greater than 23 and you don't have the permissions you just don't load the map. You have to request the permission, verify that it was given and follow your code.