Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

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());

 ----------

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...