마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 구글맵v2 오류 해결좀 부탁드립니다!!부탁드려요

0 추천

구글맵 처음이라 이러저리 소스찾아봐서 만든건데

컴퓨터로 돌리면 이렇게떠요.. 원래는 구글맵이뜨고 내현재위치가 표시 되어야합니다.

소스

-------------------------------------------------------------------------------------------------------------

 
      GooglePlayServicesUtil.isGooglePlayServicesAvailable(Map.this);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        provider = locationManager.getBestProvider(criteria, true);
        
        if(provider==null){  //위치정보 설정이 안되어 있으면 설정하는 엑티비티로 이동합니다
          new AlertDialog.Builder(Map.this)
       .setTitle("위치서비스 동의")
       .setNeutralButton("이동" ,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
})
       .show();
        }else{   //위치 정보 설정이 되어 있으면 현재위치를 받아옵니다
    locationManager.requestLocationUpdates(provider, 1, 1, Map.this);
        setUpMapIfNeeded();
        }
        
    }
    
    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {//위치설정 엑티비티 종료 후 
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
       Criteria criteria = new Criteria();
       provider = locationManager.getBestProvider(criteria, true);
       if(provider==null){//사용자가 위치설정동의 안했을때 종료 
finish();
}else{//사용자가 위치설정 동의 했을때 
locationManager.requestLocationUpdates(provider, 1L, 2F, Map.this);
        setUpMapIfNeeded();
}
break;
}
}
    
    @Override
public void onBackPressed() {
this.finish();
}
 
    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
        
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        locationManager.removeUpdates(this);
    }
    
    private void setUpMapIfNeeded() {
if (mmap == null) {
mmap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
if (mmap != null) {
setUpMap();
}
}
}
    
    private void setUpMap() {
    mmap.setMyLocationEnabled(true);
mmap.getMyLocation();
 
}
 
 
 
    boolean locationTag=true;
    
    @Override
    public void onLocationChanged(Location location) {
    if(locationTag){//한번만 위치를 가져오기 위해서 tag를 주었습니다
    Log.d("myLog"  , "onLocationChanged: !!"  + "onLocationChanged!!");
       double lat =  location.getLatitude();
       double lng = location.getLongitude();
    
Toast.makeText(Map.this, "위도  : " + lat +  " 경도: "  + lng ,  Toast.LENGTH_SHORT).show();
      locationTag=false;
    }
 
    }
 
지미니v (1,080 포인트) 님이 2013년 12월 6일 질문
핸드폰으로 돌리면 맵은안뜨고 새하얗게뜨고 확대 축소하는 버튼이랑 그 내위치로 돌아오게하는 버튼인가? 그거만뜹니다.

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...