I found this code
private void centerMapOnMyLocation() {
map.setMyLocationEnabled(true);
location = map.getMyLocation();
if (location != null) {
myLocation = new LatLng(location.getLatitude(),
location.getLongitude());
}
map.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation,
Constants.MAP_ZOOM));
}
But getMyLocation() is depricated. How i can determine my location and show this on my map at first.
My code now is:
public class FragmentMap extends Fragment implements OnMapReadyCallback {
MapView mapView;
GoogleMap map;
TextView t1, t2;
private Marker marker;
public FragmentMap() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_map, container, false);
t1 = (TextView) v.findViewById(R.id.textView);
t2 = (TextView) v.findViewById(R.id.textView2);
mapView = (MapView) v.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
return v;
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.getUiSettings().setZoomControlsEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMyLocationEnabled(true);
map.setOnMyLocationButtonClickListener(myLocationButtonClickListener);
}
private GoogleMap.OnMyLocationButtonClickListener myLocationButtonClickListener = new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
Location location = map.getMyLocation();
LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());
t1.setText(valueOf(location.getLatitude()));
t2.setText(valueOf(location.getLongitude()));
marker = map.addMarker(new MarkerOptions().position(loc));
if(map != null){
map.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f));
}
return false;
}
};
I read developers.android.com but not found the answer. I need just show my current location on the map. Noghing more