i am trying to find my location on Google Map. My code is here. I have run my app in my telephone but it's unfortunately stopped. Any ideas about what can be the problem ? Thanks.
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);
}
}