-1

I am developing an application which requires to mark the current location of an user onto google maps. I have already got the code for setting up a marker on the current location.

private void handleNewLocation(Location location) {
        Log.d(TAG, location.toString());

   //get the new latitude and longitude
        double currentLatitude = location.getLatitude();
        double currentLongitude = location.getLongitude();


        //create object to store them
        LatLng latLng = new LatLng(currentLatitude, currentLongitude);

        //create marker with the new position
        MarkerOptions options = new MarkerOptions()
                .position(latLng)
                .title("I am here!");

        //add marker to the map

        mMap.addMarker(options);

        //move camera to current location

        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    }

There are no errors shown on compilation. But when running on emulator , it displays "MapActivity has stopped working".

I am using Nexus 5 API 21x86 android virtual device to run the app.

Please help !!!!!!!

Fahim
  • 12,198
  • 5
  • 39
  • 57
Van
  • 1
  • 2
  • 2
  • Please post your Logcat . To find your Logcat, please refer to [here](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – bjiang Feb 05 '15 at 16:48
  • please check the answer posted below and guide me with the same. Thank you so very much ! – Van Feb 06 '15 at 05:53

1 Answers1

1

I think there is lots of problems, please refer to here, do it step by step, you will get the map.

Also, for the Marker part, please refer to here.

bjiang
  • 6,068
  • 2
  • 22
  • 35
  • Thank you for the link :) I do not have any errors shown on the logcat and my app does not crash anymore. Unfortunately, features like changing map type, current location and zoom in/out are not working. Just the map is displayed :( What do i do. – Van Feb 07 '15 at 04:50
  • Did you follow second [link](https://www.youtube.com/watch?v=pJguXeAk9OU)? I followed, and it worked, what's the problem?BTW, you can edit your question, you don't need to put the logcat in the answer – bjiang Feb 07 '15 at 22:17
  • I used the video tutorials for the google maps route, but what happens is that the when i press the "Get Directions/Directions" button it goes to the Original Google maps app and shows the route. My intention is to retrieve the route from google maps database/API and display the route on my app and not on Google maps – Van Feb 15 '15 at 11:29