Home get updated and lastknownlocation in a fragment
Reply: 0

get updated and lastknownlocation in a fragment

user1752
1#
user1752 Published in May 26, 2018, 9:34 pm

Being very new to java, I am very confused about getting lastknownlocation and updated location.

Over last few days, I have managed to get the mark on a predefined location, but I am struggling very much on getting my current location using fusedlocationproviderclient.

I will be grateful if somebody kindly help me on getting this. I am using :

compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'

Though not for the updated location, below is the code for marker at a fixed position

public class SecondFragment extends Fragment implements OnMapReadyCallback {

    private GoogleMap mMap;

    public GoogleMap getMap() {
    return mMap;
    }
    public static SecondFragment newInstance() {
        SecondFragment fragment = new SecondFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_maps, null, false);

        SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        return view;
    }


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

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3051 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO