-1

Hello i am completely new in android location concept, i have created one map activity in android studio. this is the code.

 public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        mMap.setMyLocationEnabled(true);

        Location location = null;
        LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
        mMap.addMarker(new MarkerOptions().position(currentPosition).title("Current Location"));

Is this is correct @Abhishek

1 Answers1

1

You can use like this

@Override
public void onMapReady(GoogleMap map) {
    // TODO Auto-generated method stub
    map.setMyLocationEnabled(true);
    LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude());
    map.addMarker(new MarkerOptions().position(currentPosition).title("Current Location"));
}

location which get from onLocationChanged method

@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
 location = new LatLng(loc.getLatitude(), loc.getLongitude());

 ----------

}
Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38
  • Thanks it worked but problem is It is not visible in marker, can you help me out for that how to use marker for my location.. – Elina Mohanty May 16 '16 at 10:47
  • what is that location, from where u got that ? where you have initialize "location".. @Abhishek – Elina Mohanty May 16 '16 at 11:27
  • public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera mMap.setMyLocationEnabled(true); Location location = null; LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude()); mMap.addMarker(new MarkerOptions().position(currentPosition).title("Current Location")); – Elina Mohanty May 16 '16 at 11:40
  • hello @Abhishek please can you give complete code, i am too new to understand. where i have to define the location can you please give in one class everything please.. – Elina Mohanty May 16 '16 at 11:46
  • please refer this http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ – Abhishek Patel May 16 '16 at 11:53