Como encontrar o local no Google Map
Eu estou tentando encontrar minha localização no Google Map. Meu código está aqui. Eu executei meu aplicativo no meu telefone, mas infelizmente ele foi interrompido. Alguma idéia sobre o que pode ser o problema? Obrigado.
public class MainActivity extends Activity implements LocationListener {
private LatLng loc ;
private LocationManager locationManager;
private String provider;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions().position(loc).title("Istanbul"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public void onLocationChanged(Location location) {
double lat = (double) (location.getLatitude());
double lng = (double) (location.getLongitude());
loc = new LatLng(lat,lng);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(provider, 400, 1, this);
}
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}
}