안녕하세요.

추운날씨에 감기 조심하십시요. ^-^)


아래와 같이 내 위치 정보를 가져오는 Code을 작성했는데 실제 동작시 LogCat에 어떠한 로그 내용도 기록되지 않습니다.

Log.d("MyTag", "MyLocation Invoked");의 내용조차 실행되지 않습니다.

따라서 결과값을 확인 할 수가 없는데, 제 코드상에 문제가 있는 걸까요?

알려주시면 감사하겠습니다. ^^)


[Code1]


Button stopService;

...

 stopService = (Button)findViewById(R.id.btn_test2);

...

   stopService.setOnClickListener(new OnClickListener(){        

@Override

public void onClick(View v) {

// 위치정보를 호출합니다.

MyLocation location = new MyLocation();

}        

        });

...


[Code2]

package com.android.besafe;


import java.io.IOException;

import java.util.List;

import java.util.Locale;

import android.app.Activity;

import android.content.Context;

import android.location.Address;

import android.location.Criteria;

import android.location.Geocoder;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle;

import android.util.Log;


public class MyLocation extends Activity implements LocationListener{ 

String provider;

LocationManager locationManager;

 

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

Log.d("MyTag", "MyLocation Invoked");

String context=Context.LOCATION_SERVICE;

locationManager=(LocationManager)getSystemService(context);

Location location = locationManager.getLastKnownLocation(bestProvider());

locationManager.requestLocationUpdates(bestProvider(),1000,0, this);

updateLocation(location);

Log.d("MyTag", "context: "+context);

}

public String bestProvider(){

Criteria criteria = new Criteria();

criteria.setAccuracy(Criteria.ACCURACY_FINE);

criteria.setAltitudeRequired(false);

criteria.setBearingRequired(false);

criteria.setSpeedRequired(true);

criteria.setCostAllowed(true);

criteria.setPowerRequirement(Criteria.POWER_LOW);

provider = locationManager.getBestProvider(criteria, true);

Log.d("MyTag", "bestProvider() Invoked");

return provider;

}

public void updateLocation(Location location) {

Log.d("MyTag","location: "+location);

if(location!=null){

double latitude = location.getLatitude();

double longitude = location.getLongitude();

List<Address> addresses = null;

Geocoder gc = new Geocoder(this, Locale.getDefault());

try{

addresses = gc.getFromLocation(latitude, longitude, 1);

String now_address = addresses.get(0).getAddressLine(0);

Log.d("MyTag","현재위치: "+now_address);

}catch(IOException e){

e.printStackTrace();

}catch(Exception e){

e.printStackTrace();

}

}

}

protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}


@Override

public void onLocationChanged(Location location) {

// TODO Auto-generated method stub

}


@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

}

}