現在地を取得できません。それは常にクラッシュします。私はすべてをチェックしました。誰か私の居場所を見つけるのを手伝ってくれませんか?
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(isGooglePlay()){
setContentView(R.layout.map);
setupmapifneeded();
}
}
private void setupmapifneeded() {
if(map==null){
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}if(map!=null){
map.setMyLocationEnabled(true);
LocationManager mlm = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria c = new Criteria();
String provider = mlm.getBestProvider(new Criteria(), false);
if(provider == null){
onProviderDisabled(provider);
}
Location mylocation = mlm.getLastKnownLocation(provider);
if(mylocation != null){
onLocationChanged(mylocation);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
private boolean isGooglePlay(){
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(status == ConnectionResult.SUCCESS){
return true;
}else{
((Dialog)GooglePlayServicesUtil.getErrorDialog(status, this, 10)).show();
//Toast.makeText(this, "nai", Toast.LENGTH_LONG).show();
}
return false;
}
@Override
public void onLocationChanged(Location mylocation) {
double lat = mylocation.getLatitude();
double longi = mylocation.getLongitude();
LatLng latlng = new LatLng(lat,longi);
map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
map.animateCamera(CameraUpdateFactory.zoomTo(10));
}