public void GetLocations() {
TextView latText = (TextView) findViewById(R.id.tvLatitude);
TextView lngText = (TextView) findViewById(R.id.tvLongitude);
TextView jusoText = (TextView) findViewById(R.id.tvAddress);
StringBuffer juso = new StringBuffer();
if (myLocation != null) {
latPoint = myLocation.getLatitude();
lngPoint = myLocation.getLongitude();
try {
// 위도,경도를 이용하여 현재 위치의 주소를 가져온다.
List<Address> addresses;
addresses = geoCoder.getFromLocation(latPoint, lngPoint, 1);
for (Address addr : addresses) {
int index = addr.getMaxAddressLineIndex();
for (int i = 0; i <= index; i++) {
juso.append(addr.getAddressLine(i));
juso.append(" ");
}
juso.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
latText.setText(String.valueOf(latPoint));
lngText.setText(String.valueOf(lngPoint));
jusoText.setText(String.valueOf(juso));
k = String.valueOf(latPoint);
j = String.valueOf(lngPoint);
i = String.valueOf(juso);
}
---------------------------------------------------------------------------------------
GetLocations() 정의해준겁니다.
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
sqldb = db.getWritableDatabase();
Cursor cursor = sqldb.rawQuery("SELECT * FROM CallDB;",null);
while(cursor.moveToNext()){
b = cursor.getString(0);
}
String a="sms:ok";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("0"+b, null, "위도:"+k+"경도:"+j+"주소:"+i, null, null);
Toast.makeText(getApplicationContext(),a , Toast.LENGTH_SHORT).show();
cursor.close();
sqldb.close();
}
});
}
-------------------------------------------------------------------------------------------
GetLocations() 로인해 얻어진 위치값을 문자로 전송해주는 코드입니다
.
gpsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GetLocations();
}
});
이렇게 해줄경우 버튼클릭하면 정상적으로 위치값 받아오는데
그냥
GetLocations(); 만 쓸경우 위치값을 왜 못받아오는 걸가요 이유좀 알려주세요.