Quiero crear un Boton que me diga exactamente donde se encuentra mi dispocitivo, y que me lo senale en un MapView, eh intentado hacerlo de algunas maneras pero no lo eh conseguido.
Por ahora este es codigo que tengo :
public class CameraFragment extends Fragment implements OnMapReadyCallback{
double latitude, longitude;
Button myplacebtn;
MapView mapView;
GoogleMap map;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.camera_fragment, container, false);
myplacebtn = (Button) view.findViewById(R.id.myplacebtn);//Button --get my location
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
//get a MapView
mapView.getMapAsync(new OnMapReadyCallback() {
public static final int MY_REQUEST_INT = 177;
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
// Setting a click event handler for the map
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(latLng);
setCoordinates.setText(latLng.latitude + " , " + latLng.longitude);
latitude = latLng.latitude;
longitude = latLng.longitude;
// Setting the title for the marker.
// This will be displayed on taping the marker
markerOptions.title(latLng.latitude + " : " + latLng.longitude);
// Clears the previously touched position
map.clear();
// Animating to the touched position
map.animateCamera(CameraUpdateFactory.newLatLng(latLng));
// Placing a marker on the touched position
map.addMarker(markerOptions);
}
});
map.getUiSettings().setMyLocationButtonEnabled(false);
LatLng jerusalem = new LatLng(32.1105435, 34.8683683);
CameraUpdate miLocation = CameraUpdateFactory.newLatLngZoom(jerusalem, 11);
map.moveCamera(CameraUpdateFactory.newLatLng(jerusalem));
googleMap.animateCamera(miLocation);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(jerusalem);
if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(),
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.INTERNET}, MY_REQUEST_INT);
}
return;
} else {
googleMap.setMyLocationEnabled(true);
}
googleMap.getUiSettings().setZoomControlsEnabled(true);
}
});
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
eh intentado utilizar el LocationListener
pero me da error