0

So I did this: File Build.gradle:

compile 'com.google.android.gms:play-services:4.2.42'

Manifest:

<uses-permission android:name="com.example.angyy.home3.permissions.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<meta-data android:name="com.google.android.maps.v2.API_KEY"
            android:value="(my key)"/>

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

Main:

map=((MapFragment) getFragmentManager().findFragmentById(R.id.fragment1)).getMap();
            MarkerOptions k = new MarkerOptions()
                    .position(new LatLng(40.6453157,-7.9209911))
                    .title("Escola Superior Tecnologia Viseu")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.estvfoto))
                    .draggable(true).snippet("Near something something");
            map.addMarker(k);
            map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            map.setMyLocationEnabled(true);
            map.getUiSettings().setZoomControlsEnabled(true);
            map.getUiSettings().setZoomGesturesEnabled(true);
            map.getUiSettings().setCompassEnabled(true);
            map.getUiSettings().setMyLocationButtonEnabled(true);
            map.getUiSettings().setRotateGesturesEnabled(true);
            map.getUiSettings().setTiltGesturesEnabled(true);

            CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(40.6453157,-7.9209911)).zoom(15).build();

            map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

the map is showing and the gestures are working, but it's not going to the location I put there.. What am I missing? (No errors...)

AL.
  • 36,815
  • 10
  • 142
  • 281
Angela
  • 1
  • 1
  • `animateCamera` can be cancelled if the user interacts with the map before the animation has ended. If you want to prevent this you can use `moveCamera` (the move is instantaneous). Does your map center your desired location if yu use `movecamera`? – antonio May 10 '16 at 11:24
  • `getMap` is already deprecated. Why still use it? – AL. May 10 '16 at 11:32
  • Check this http://stackoverflow.com/questions/31371865/replace-getmap-with-getmapasync – Android Enthusiast May 11 '16 at 10:58

1 Answers1

0

If you are doing this inside onCreate method then do this.

    onCreate(){

        try{
            initialiseMap();
        }catch( Exception e){
            e.printStackTrace();
        }
}




 public void initialiseMap() {



    if (googleMap == null) {
        googleMap = ( (MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

        //Toast.makeText(getApplicationContext(),"Location"+lattitude+"/n"+longitude,Toast.LENGTH_SHORT).show();

        MarkerOptions marker = new MarkerOptions().position(new LatLng(YOUR CO-ORDINATES)).title("Location");
        googleMap.addMarker(marker);
        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(lattitude,longitude)).zoom(12).build();
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        Toast.makeText(getApplicationContext(),"Location"+lattitude+"/n"+longitude,Toast.LENGTH_SHORT).show();

        // check if map is created successfully or not
        if (googleMap == null) {

            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
    protected void onResume() {
        super.onResume();
        initializeMap();
    }
Sharad Chauhan
  • 4,821
  • 2
  • 25
  • 50