1

Inside navigation drawer activity, i have implemented Google Map with satellite view and location. It is working fine with Samsung galaxy s-4 (jelly bean 5.0.1) but same code if you run on Marshmallow (6.0.1), its just opening map (not showing location and not showing satellite view)

Here is the code of activity

public class NavigationDrawerPeaceNow extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_drawer_peace_now);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //---------------Setting up map-----------//

        ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                map = googleMap;
                if (ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                LatLng israel = new LatLng(31.0461, 34.8516);
                map.addMarker(new MarkerOptions().position(israel).title("israel"));
                map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                CameraPosition camPos = new CameraPosition.Builder().target(new LatLng(31.0461, 34.8516)).zoom(8).tilt(70).build();
                CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos);
                googleMap.animateCamera(camUpd3);
            }
        });

I tried searching in google but solutions was available for "satelliteview" not for this scenario. I am new to android

Thanks in advance

1 Answers1

0

The issue is in the:

if (ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    return;
}

condition: return executed if one or both permissions not granted. Try grant (for example in Applications menu) both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions for your app or change condition to:

if (ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(NavigationDrawerPeaceNow.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    LatLng israel = new LatLng(31.0461, 34.8516);
    map.addMarker(new MarkerOptions().position(israel).title("israel"));
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    CameraPosition camPos = new CameraPosition.Builder().target(new LatLng(31.0461, 34.8516)).zoom(8).tilt(70).build();
    CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos);
    googleMap.animateCamera(camUpd3);;
}

or something like that if you want to continue in case of one permission granted. (May be everything is Ok on Samsung galaxy s-4 (jelly bean 5.0.1) probably because you grant permissions earlier and didn't uninstall app).

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • thank you sir ... just removed unnecessary permissions from manifest and it works. Thanks for your help @Andrii –  Sep 27 '17 at 10:26
  • sir... Already accepted but reputation is below 15 so it will be showing to you when i will have 15 reputation. Thanks a ton sir i am so fortunate that in i have got answer from a doctorate researcher :) –  Sep 27 '17 at 10:59
  • Seems you try upvote, but not accept the answer. You can accept answer with any reputation. To do this you should click the checkmark under question rate, on the left right below the vote arrows ant it's should become green. And sometimes doctorate researcher is also developers, like you :) Good luck! – Andrii Omelchenko Sep 27 '17 at 11:18
  • Done!! ... thank you so much sir.. i am new here and working on a project which contains MAPS and KMZ files. Is there any way to connect you sir so that i can discuss with you in future? I am sure i will not find a mentor like you. :) –  Sep 27 '17 at 11:27
  • Hmm... Let me think about it... Anyway you can ask questions here. – Andrii Omelchenko Sep 27 '17 at 13:07
  • can you suggest steps to load KMZ files into maps ?? or any tutorial –  Sep 27 '17 at 13:29
  • KMZ is zipped KML, so you should unzip KMZ (like in [that](https://stackoverflow.com/q/3382996/6950238) question) and get KML. Than add `KmlLayer` to your `GoogleMap` object like described in [Official Documentation](https://developers.google.com/maps/documentation/android-api/utility/kml) or in [that](https://stackoverflow.com/a/45563585/6950238) answer. – Andrii Omelchenko Sep 27 '17 at 14:08
  • sir.. i am very grateful to you ... thank you so much :) –  Sep 27 '17 at 14:13