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 ? Than
// try this
**main.xml**
public class MyActivity extends FragmentActivity {
public static LocationManager mlocManager;
public static LocationListner mListner;
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = getMapView();
map.setMyLocationEnabled(true);
try {
mlocManager = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
mListner = new LocationListner();
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
try {
mlocManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, mListner);
} catch (Throwable e) {
e.printStackTrace();
}
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListner);
} catch (Throwable e) {
e.printStackTrace();
}
try {
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mListner);
} catch (Throwable e) {
e.printStackTrace();
}
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
public GoogleMap getMapView() {
FragmentManager fm = getSupportFragmentManager();
SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.maps);
// Getting GoogleMap object from the fragment
return f.getExtendedMap();
}
public void setMapMarker(LatLng loc){
map.addMarker(new MarkerOptions().position(loc).title("Istanbul"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
class LocationListner implements LocationListener {
@Override
public void onLocationChanged(Location location) {
setMapMarker(new LatLng(location.getLatitude(),location.getLongitude()));
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}